On 2005-05-25 15:59:28 +0100, Dave Korn wrote: > ----Original Message---- > >From: chris jefferson > >Sent: 25 May 2005 15:23 > > 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;
No, it is valid. Whether you should do that or use another method depends on the context. In particular, if you can make sure that your computations are exact, there's no problem in using != or ==. You can also choose to control the rounding (when possible). > 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. If you do computational geometry, such kinds of things would not be sufficient. -- Vincent Lefèvre <[EMAIL PROTECTED]> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / SPACES project at LORIA