View Single Post
  #4  
Old July 24th 03, 02:21 PM
Tim Prince
external usenet poster
 
Posts: n/a
Default

Jack Klein wrote:

On 15 Jul 2003 19:25:24 -0700, (Dylan
Nicholson) wrote in comp.lang.asm.x86:

The following C code:

float f = 5.15002;
double d = 5.15002;
if (d + FLT_EPSILON f)
puts("huh?");

Where 'FLT_EPSILON' is defined as the minimum number whereby 1.0 +
FLT_EPSILON != 1.0, causes the string "huh!" to be printed out on my
system (Pentium III)
I have included the relevant assembly code below.
Now is this a bug in the intel chip, or allowable because FLT_EPSILON
makes no promises when added to numbers greater than 1.0?

It doesn't happen when 'd' is another float, so presumably it has
something to do with double-precision/single-precision conversions
too.

Curious...

Dylan


[snip]

You're misunderstanding the meaning of FLT_EPSILON.

If you want to check the minimum representable difference between the
float representation of 10.0 and the next higher float value, you need
to use FLT_EPSILON * 10. If you were checking a value around 100, you
would need to use FLT_EPSILON * 100.

"close enough for government work" More accurately, FLT_EPSILON times the
largest integer power of FLT_RADIX which is less than the number to be
compared. 4*FLT_EPSILON in the case above. Not a good idea to redefine a
constant defined by Standard C, as the OP implies he is doing.
--
Tim Prince