Re: [Cppunit-devel] assertDoubleEquals, NaN & Microsoft Visual Studio 6
Brought to you by:
blep
From: CppUnit d. m. l. <cpp...@li...> - 2007-02-25 04:29:44
|
Hi Baptiste, I'm unclear on what problem you are solving here. My guess is that CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, nan, 1.0 ) was passing when it should in fact fail. Is that the case? Also: why did you make the following change in =20 examples/cppunittest/TestAssertTest.cpp? What does the comment mean? - CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, =20 0.0, 1.0 ) ); + CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, =20 0.0, 1.0 ) ); // this one fails Quoting CppUnit development mailing list =20 <cpp...@li...>: > This seems to confirm that MSVC6 code generator is bug (does not respect > IEEE-754 standard in spite of what the doc claim). > > To work-around this, I added an explicit test for NaN value when testing > non-finite value for equalities. Here is the function: > // To work around this, a NaN is assumed to be detected if no strict > ordering is found. > inline bool floatingPointIsUnordered( double x ) > { > // x !=3D x will detect a NaN on conformant platform > // (2.0 < x && x < 1.0) will detect a NaN on non conformant platform: > // =3D> no ordering can be found for x. > return (x !=3D x) || (2.0 < x && x < 1.0); > } I don't understand why this works for you. According to the standard =20 (see e.g. page 8 of =20 http://www.cs.berkeley.edu/~wkahan/ieee754status/ieee754.ps) all =20 comparisons with NaN are false except "x !=3D x", which is true. You =20 state that MSVC6 gets "x !=3D x" wrong. Does it also get "x < y" wrong =20 and return true? > I'm not an expert on floating-point manipulation & NaN. Does any one see > anything wrong on the above implementation or the comments? The section of the paper referenced above also states that all =20 comparisons with NaN, except =3D=3D and !=3D, are *invalid* and thus signal.= =20 So the code you wrote is going to cause a problem if the FPU signals =20 are enabled. If we need this function, can we rename it floatingPointIsNan()? Then =20 I can create suitable automakery to use the standard isnan() on =20 systems that have it. On that note, does MSVC6 have something like =20 isnan(), maybe called _isnan()? http://msdn2.microsoft.com/en-us/library/tzthab44(VS.80).aspx Cheers, -Steve |