View Single Post
  #3  
Old July 17th 03, 04:12 AM
Jack Klein
external usenet poster
 
Posts: n/a
Default

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.

--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq