walkingcarcass 116 Report post Posted July 7, 2003 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. 0 Share this post Link to post Share on other sites

Beer Hunter 712 Report post Posted July 7, 2003 My memory is a bit off and I''m lazy, so these mightn''t be quite right:IEEE floats: 2^{105}, give or take a few orders of magnitude.IEEE doubles: 2^{971}, give or take a few orders of magnitude.If you want to get the numbers exactly, you can find the format here. 0 Share this post Link to post Share on other sites

S1CA 1418 Report post Posted July 7, 2003 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''Connorex -Creative AsylumProgrammer &Microsoft MVP 0 Share this post Link to post Share on other sites

sjelkjd 171 Report post Posted July 7, 2003 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). 0 Share this post Link to post Share on other sites

walkingcarcass 116 Report post Posted July 8, 2003 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 */ [/codeGreat, but does it hold for, say, 100000000+FLT_EPSILON!=100000000 or 0.000000001+FLT_EPSILON!=0.000000001? ********I am not the Iraqi information minister. 0 Share this post Link to post Share on other sites

sjelkjd 171 Report post Posted July 9, 2003 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. 0 Share this post Link to post Share on other sites