what is the smallest and largest values for type double
Answers
Largest Double- and Single-Precision Numbers
The MATLAB command realmax returns the largest value that you can represent as a double-precision floating-point number.
realmax
ans =
1.7977e+308
When the result of an operation on numbers of type double exceeds realmax, MATLAB returns Inf.
Similarly, the MATLAB command realmax('single') returns the largest value that you can represent as a single-precision number.
realmax('single')
ans =
3.4028e+038
Note that realmax for type double is much larger than realmax('single'), because the range of numbers that you can represent in single-precision is more limited than in double-precision.
When the result of an operation on numbers of type single exceeds realmax('single'), MATLAB returns Inf of class single. For example,
(realmax('single')/2)^2
ans =
Inf
Because realmax is larger than realmax('single'), performing the same computation in double precision returns a finite answer.
(double(realmax('single'))/2)^2
ans =
2.8948e+076
Smallest Positive Double- and Single-Precision Numbers
The MATLAB command realmin returns the smallest positive normalized floating-point number that you can represent in double precision.
realmin
ans =
2.2251e-308
When the result of a computation on numbers of type double is a positive number that is less than realmin, MATLAB returns either 0 or a subnormal floating-point number, that is, one that is not in standard form.
Similarly, there is a smallest positive normalized floating-point number that you can represent in single precision, whose value is returned by realmin('single').
realmin('single')
ans =
1.1755e-038
Because realmin is less than realmin('single'), operations that return a nonzero double-precision result in standard form might return 0 or a subnormal answer when you do the same operations in single precision.