Jump to content
  • Advertisement

Archived

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

walkingcarcass

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!