By Nasser Abbasi. January 29, 2002.
Question: For you computer system find (a) the largest possible floating point number; (b) the largest integer I such that (I+1)-1 equals I; (c) the smallest possible positive floating point number; (d) the smallest positive floating-point number x such that (1+x)-1 does not equal zero.
Answer.
Using matlab.
(a)
» help realmax
REALMAX Largest positive floating point number.
x = realmax is the largest floating point number representable
on this computer. Anything larger overflows.
See also EPS, REALMIN.
» realmax
ans =
1.7977e+308
» format long
» realmax
ans =
1.797693134862316e+308
(b)
%To solve this, I use bitmax.
» help bitmax
BITMAX Maximum floating point integer.
BITMAX returns the maximum unsigned floating point integer for
this machine. It is the value when all bits are set.
On IEEE machines, this is the value 2^53-1;
» x=bitmax
x =
9.007199254740991e+015
» isequal( (x+1)-1, x)
ans =
1
» x=x+1
x =
9.007199254740992e+015
» isequal( (x+1)-1, x)
ans =
0
% Hence, the largest integer x such that (x+1)-1 equals x
is 9.007199254740991e+015
( c )
% I use matlab relamin to find the answer
» help realmin
REALMIN Smallest positive floating point number.
x = realmin is the smallest positive normalized floating point
number on this computer. Anything smaller underflows or is
an IEEE "denormal".
See also EPS, REALMAX.
» realmin
ans =
2.225073858507201e-308
(d)
%here we want to find the floating point accuracy. Using Matlab
» help eps
EPS Floating point relative accuracy.
EPS returns the distance from 1.0 to the next largest
floating point number. EPS is used as a default tolerance by
PINV and RANK, as well as several other MATLAB functions.
» isequal( (1+eps)-1,0)
ans =
0
» isequal( (1+eps/2)-1,0)
ans =
1
» eps
ans =
2.220446049250313e-016
% The above shows that eps is the smallest positive floating-point number x such that
% (1+x)-1 does not equal zero.