Floating point technical question

Started by
4 comments, last by walkingcarcass 20 years, 9 months ago
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.
spraff.net: don't laugh, I'm still just starting...
Advertisement
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.
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

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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).
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.
spraff.net: don't laugh, I'm still just starting...
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.

This topic is closed to new replies.

Advertisement