Archived

This topic is now archived and is closed to further replies.

walkingcarcass

Floating point technical question

Recommended Posts

walkingcarcass    116
What is the biggest error in representing a float (or double)? ie what is the biggest gap between any two consecutive representable numbers? ******** I am not the Iraqi information minister.

Share this post


Link to post
Share on other sites
Beer Hunter    712
My memory is a bit off and I''m lazy, so these mightn''t be quite right:

IEEE floats: 2105, give or take a few orders of magnitude.
IEEE doubles: 2971, give or take a few orders of magnitude.

If you want to get the numbers exactly, you can find the format here.

Share this post


Link to post
Share on other sites
S1CA    1418
The values are also defined in the <float.h> header as Epsilon:


#define DBL_EPSILON 2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */

#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */


--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Share this post


Link to post
Share on other sites
sjelkjd    171
quote:
Original post by walkingcarcass
What is the biggest error in representing a float (or double)? ie what is the biggest gap between any two consecutive representable numbers?



It''s not a constant number. This is because you only get a constant amount of mantessa, even though the exponent changes. So say you have 23 bits of mantessa in a float, that means that if your exponent is 0(representing numbers in the range 0-1), the space between adjacent numbers is 2^-24. However, if your exponent is 100(let''s say), then the space between adjacent numbers is 2^(-24+100).

Share this post


Link to post
Share on other sites
walkingcarcass    116
quote:

#define DBL_EPSILON 2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */

#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */
[/code

Great, but does it hold for, say, 100000000+FLT_EPSILON!=100000000 or 0.000000001+FLT_EPSILON!=0.000000001?


********


I am not the Iraqi information minister.

Share this post


Link to post
Share on other sites
sjelkjd    171
Since it appears you didn''t infer it from my previous post, the distance between a floating point number and it''s successor is
2^(exponent-#of mantessa bits)
32 bit floats have 23 bits of mantessa. I don''t remember off hand how many bits doulbes have, it''s probably about 51.

Share this post


Link to post
Share on other sites