function imax = intmax(classname)
% Embedded MATLAB Library function.
%
% Limitations:
% Only 8, 16, and 32 bit signed and unsigned integer types are supported.

% Copyright 2002-2004 The MathWorks, Inc.

if (nargin == 0)
    imax = int32(2147483647);
else
    eml_assert(ischar(classname),'Input must be a string, the name of an integer class.');
    switch (classname)
      case 'int8'
        imax = int8(127);
      case 'uint8'
        imax = uint8(255);
      case 'int16'
        imax = int16(32767);
      case 'uint16'
        imax = uint16(65535);
      case 'int32'
        imax = int32(2147483647);
      case 'uint32'
        imax = uint32(4294967295);
      case 'int64'
        % Turn off the overflow warning because the constant value below
        % is interpreted as the closest double value, namely 2^63.
        % This is out of range and warns of overflow upon conversion to int64.
        %s = warning('query','MATLAB:intConvertOverflow');
        %warning('off','MATLAB:intConvertOverflow');
        %imax = int64(9223372036854775807);
        %warning(s);
        eml_assert(0,'Integer class "int64" not supported.');
      case 'uint64'
        % Turn off the overflow warning because the constant value below
        % is interpreted as the closest double value, namely 2^64.
        % This is out of range and warns of overflow upon conversion to uint64.
        %s = warning('query','MATLAB:intConvertOverflow');
        %warning('off','MATLAB:intConvertOverflow');
        %imax = uint64(18446744073709551615);
        %warning(s);
        eml_assert(0,'Integer class "uint64" not supported.');
      otherwise
        eml_assert(0,'Invalid class name.');
    end
end
