RE: [Algorithms] Floating point comparison.
Brought to you by:
vexxed72
From: Jay P. <Jp...@bl...> - 2001-06-30 01:43:56
|
In a similar vein MSVC has the "improve floating point consistency" to avoid problems caused by intermediate results not matching the memory version, i.e: float c = F( -- an inline func which is supposed to always return a value <= 1 --); ASSERT(c <= 1.0f); d = c * .... In debug the ASSERT never fired because VC wrote the results into memory which causes the number to be converted from 64+ bits to 32 bits, while in release the compiler used the 64+ bit value on the FPU stack and the ASSERT fired every so often. (we leave assertions on in release for internal builds). -Jay -----Original Message----- From: Kent Quirk [mailto:ken...@co...] Sent: Friday, June 29, 2001 6:11 PM To: gda...@li... Subject: Re: [Algorithms] Floating point comparison. 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/ _____________________________|_________________________________________ _______________________________________________ GDAlgorithms-list mailing list GDA...@li... http://lists.sourceforge.net/lists/listinfo/gdalgorithms-list |