Re: [Cppunit-devel] CPPUNIT_ASSERT_DOUBLES_EQUAL() with non-finite numbers
Brought to you by:
blep
From: CppUnit d. m. l. <cpp...@li...> - 2006-11-20 10:31:58
|
CppUnit development mailing list wrote: >> C99 is non-standard in the context of C++, which is a superset of C90. >> So, all C++ compilers might not support this. > > True, they might not; do you know of a current compiler that has > neither isfinite() nor the older, BSD finite()? You're right, I don't. Then again, I'm sure I don't know all compilers currently in use. I prefer to erring to side of caution as it isn't standard. > Hmm. Now that I think of it, just flipping the expression from > testing "is not equal" to "is equal" fixes the problem with NaNs > anyway: all boolean expressions involving a NaN are false. > Maybe we don't need the isfinite() test after all ... or maybe > we do; I can't remember whether "Inf - Inf" evaluates to 0. Inf - Inf evaluates to NaN. But that assumes the right signs, I think. How about (0.0 * <x>)? That should evaluate to NaN only if <x> is Inf, -Inf or NaN. So something like ((0.0 * <x>) == 0.0), if not optimized away, should be equal to finite(<x>). http://steve.hollasch.net/cgindex/coding/ieeefloat.html -- Tuomo |