function iAmin = intmin(A)
% MATLAB Code Generation library function for the @fi/intmin

% $INCLUDE(DOC) toolbox/eml/lib/fixedpoint/@embedded/@fi/intmin.m $
% Copyright 2002-2017 The MathWorks, Inc.
%#codegen
  
eml_allow_mx_inputs;

% Check for correct number of input arguments i.e. 1
eml_invariant(nargin==1, 'fixed:coder:incorrectNumberOfInputs');

if isfixed(A)
    % Fixed point FI

    % Get the word length of & signedness of A
    Ta  = numerictype(A);
    Fa = eml_fimath(A);
    wlA = coder.const(get(Ta,'WordLength'));
    isSignedA = coder.const(get(Ta,'Signed'));

    if isSignedA
        Tout = numerictype(1,wlA,0);
        iTemp = eml_cast(-2^(wlA-1),Tout,Fa);
    else
        Tout = numerictype(0,wlA,0);
        iTemp = eml_cast(0,Tout,Fa);
    end

    if ~coder.const(eml_fimathislocal(A))
        iAmin = eml_fimathislocal(iTemp,false);
    else
        iAmin = iTemp;
    end
    
elseif isscaleddouble(A)
    Ta  = numerictype(A);
    Fa = eml_fimath(A);
    wlA = Ta.WordLength;
    isSignedA = Ta.Signed;
    Tout = numerictype(isSignedA, wlA, 0, 'DataType', 'ScaledDouble');
    iTemp = fi(0 - (isSignedA * (2 ^ (wlA - 1))), Tout, Fa);
    if ~coder.const(eml_fimathislocal(A))
        iAmin = eml_fimathislocal(iTemp,false);
    else
        iAmin = iTemp;
    end        
    
elseif isfloat(A)
    % True Double or True Single FI
    iAmin = lowerbound(A);
else
    % FI datatype not supported
    eml_fi_assert_dataTypeNotSupported('INTMIN');
end
