time | calls | line |
---|
| | 1 | function imax = intmax(varargin)
|
| | 2 | %INTMAX Largest positive integer value.
|
| | 3 | % X = INTMAX is the largest positive value representable in an int32.
|
| | 4 | % Any value that is larger than INTMAX will saturate to INTMAX when
|
| | 5 | % cast to int32.
|
| | 6 | %
|
| | 7 | % INTMAX('int32') is the same as INTMAX with no arguments.
|
| | 8 | %
|
| | 9 | % INTMAX(CLASSNAME) is the largest positive value in the integer class
|
| | 10 | % CLASSNAME. Valid values of CLASSNAME are 'int8', 'uint8', 'int16',
|
| | 11 | % 'uint16', 'int32', 'uint32', 'int64' and 'uint64'.
|
| | 12 | %
|
| | 13 | % See also INTMIN, REALMAX.
|
| | 14 |
|
| | 15 | % Copyright 1984-2009 The MathWorks, Inc.
|
| | 16 |
|
| 6 | 17 | if (nargin == 0)
|
| | 18 | imax = int32(2147483647);
|
| 6 | 19 | elseif (nargin == 1)
|
| 6 | 20 | classname = varargin{1};
|
| 6 | 21 | if ischar(classname)
|
| 6 | 22 | switch (classname)
|
| 6 | 23 | case 'int8'
|
| | 24 | imax = int8(127);
|
| 6 | 25 | case 'uint8'
|
| | 26 | imax = uint8(255);
|
| 6 | 27 | case 'int16'
|
| | 28 | imax = int16(32767);
|
| 6 | 29 | case 'uint16'
|
| | 30 | imax = uint16(65535);
|
| 6 | 31 | case 'int32'
|
| | 32 | imax = int32(2147483647);
|
| 6 | 33 | case 'uint32'
|
| 6 | 34 | imax = uint32(4294967295);
|
| | 35 | case 'int64'
|
| | 36 | imax = int64(9223372036854775807);
|
| | 37 | case 'uint64'
|
| | 38 | imax = uint64(18446744073709551615);
|
| | 39 | otherwise
|
| | 40 | error(message('MATLAB:intmax:invalidClassName'))
|
| | 41 | end
|
| | 42 | else
|
| | 43 | error(message('MATLAB:intmax:inputMustBeString'))
|
| | 44 | end
|
| | 45 | else % nargin > 1
|
| | 46 | error(message('MATLAB:intmax:tooManyInputs'));
|
| | 47 | end
|