#### Archived

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

# Floating point technical question

This topic is 5489 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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 on other sites
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 on other sites
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.

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002076
×