Re: [Algorithms] Floating point comparison.
Brought to you by:
vexxed72
From: Kent Q. <ken...@co...> - 2001-06-30 01:10:33
|
Jay Patel wrote: > So the fact that the compiler feels motivated to use FPU instructions either > means it's lame (unlikely) or there are floating point numbers with > differing bit patterns that are equal. Other than +0 and -0 I can't think of > any. You really don't want to be comparing floating point numbers for equality, anyway, except maybe for 0. > and <, yes. But it's usually a really bad idea to test for exact bit comparisons. We had some code once that said something like: if (floatval/255.0 == 1.0) { ... } And it worked fine in debug mode, and failed in the release build. Turns out that in debug mode it was doing the divide, but in the release build it changed it to: if (floatval * (1.0/255.0) == 1.0) { ... } The result was not QUITE the same. Kent -- ----------------------------------------------------------------------- Kent Quirk | MindRover: "Astonishingly creative." Game Architect | Check it out! ken...@co... | http://www.mindrover.com/ _____________________________|_________________________________________ |