CppUnit development mailing list wrote:
> 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?
Yes. I should have put this first. All the following unit tests were
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, 0.0,
1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, nan,
1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, inf,
1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, nan,
1.0 ) );
This was caused by the fact that
equal = expected == actual;
always evaluated to true whenever expected or actual was a NaN.
> Also: why did you make the following change in
> examples/cppunittest/TestAssertTest.cpp? What does the comment mean?
> - CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan,
> 0.0, 1.0 ) );
> + CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan,
> 0.0, 1.0 ) ); // this one fails
Ignore the comment, I forgot to remove it. It's done now.
I hope it's clearer now.
> Quoting CppUnit development mailing list
>> 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 != x will detect a NaN on conformant platform
>> // (2.0 < x && x < 1.0) will detect a NaN on non conformant
>> platform: // => no ordering can be found for x.
>> return (x != x) || (2.0 < x && x < 1.0);
> I don't understand why this works for you. According to the standard
> (see e.g. page 8 of
> http://www.cs.berkeley.edu/~wkahan/ieee754status/ieee754.ps) all
> comparisons with NaN are false except "x != x", which is true. You
> state that MSVC6 gets "x != x" wrong. Does it also get "x < y" wrong
> 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
> comparisons with NaN, except == and !=, are *invalid* and thus signal.
> So the code you wrote is going to cause a problem if the FPU signals
> are enabled.
> If we need this function, can we rename it floatingPointIsNan()? Then
> I can create suitable automakery to use the standard isnan() on
> systems that have it. On that note, does MSVC6 have something like
> isnan(), maybe called _isnan()?
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to
> share your opinions on IT & business topics through brief surveys-and
> earn cash
> Cppunit-devel mailing list