Detailed explanation of code that determines the Machine Epsilon for single and double precision numbers?
4 views (last 30 days)
Show older comments
The following code was used to determine the machine epsilon for single and double precision numbers:
numprec=double(1.0); % Define 1.0 with double precision
numprec=single(1.0); % Define 1.0 with single precision
while(1 < 1 + numprec)
numprec=numprec*0.5;
end
numprec=numprec*2
Questions: Why do we consider addition to 1? Explain in detail what the code does.
0 Comments
Answers (1)
Walter Roberson
on 26 Jan 2017
Machine epsilon is, by tradition, measured with relationship to 1.
The code is looping through finding the largest number numprec such that 1 differs from 1+numprec . That is the basic definition of machine epsilon.
1 Comment
Steven Lord
on 26 Jan 2017
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!