----Original Message---- >From: chris jefferson >Sent: 25 May 2005 15:23
> Vincent Lefevre wrote: >> >> float x = 30.0; >> int main() >> { >> if ( 90.0/x != 3.0) >> abort(); >> return 0; >> } >> >> fails with -ffast-math (on x86). I would not recommend it, unless >> the user knows all the consequences. >> >> >> > On the other hand, in general using != and == on floating point numbers > is always dangerous if you do not know all the consequences. For > example, on your above program if I use 30.1 and 90.3, the program fails > without -ffast-math. I second that. It's simply not valid to use != or == to compare floating point numbers; the standard idiom is and always has been to subtract them and then see if the delta is less than or greater than some suitably-chosen epsilon. You have to regard floating point numbers as if they were more-or-less random in the lowest few bits after any amount of computation on them; the chance of getting an exact match is small. So never mind -ffast-math; I wouldn't recommend using floating point *at all* unless the user is well aware of the consequences! cheers, DaveK -- Can't think of a witty .sigline today....