Range of numerical values

What range of numerical values can be entered in MATLAB R2021a?

Answers (1)

KSSV
KSSV on 28 Aug 2021
Read about single and double floating point numbers.
Range of single: 2^(-126) to 2^(127)
Range of double: 2^(-1022) to 2^(1023).
If you use symbolic tool box, you can prescribe your required precision.

2 Comments

<help/matlab/numeric-types> has all the various native data types and their ranges plus the various functions available that return information regarding them.
As far as the Q? buried in the tag (don't do that, by the way in future, not the purpose of a tag), inf is NOT the largest value that can be entered; inf is not actually a value but a flag that the value is greater or less than the (signed) range for a floating point variable and can only be generated by an operation such as 1/0, use of the builtin inf function or by casting from the hex respresentation. See <infinity-and-nan>.
The largest values are given by
>> realmax("double"), realmax('single')
ans =
1.7977e+308
ans =
single
3.4028e+38
>>
All this is in the documentation linked to above on data types. Also read up on IEEE-754 -- probably the most approachable in depth resource there is <Goldberg -- What Every Computer Scientist Should Know About Floating Point Arithmetic>>
The smallest magnitude numbers are not exactly what KSSV indicated.
log2(realmin('single'))
ans = single -126
log2(eps(realmin('single')))
ans = single -149
log2(realmin('double'))
ans = -1022
log2(eps(realmin('double')))
ans = -1074
The numbers between 2^-149 and 2^-126 (single precision) or 2^-1074 and 2^-1022 (double precision) are stored in a different format known as "denormalized numbers". The denormalized numbers are effectively fixed-point rather than floating point -- so in the case of single precision, a denormalized number would be an integer times 2^-149 and in the case of double precision, a denormalized number would be an integer times 2^-1074 .

Sign in to comment.

Asked:

on 28 Aug 2021

Commented:

on 28 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!