summaryrefslogtreecommitdiff
path: root/src/cppunit
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit')
-rw-r--r--src/cppunit/TestAssert.cpp33
-rw-r--r--src/cppunit/cppunit.dsp4
2 files changed, 20 insertions, 17 deletions
diff --git a/src/cppunit/TestAssert.cpp b/src/cppunit/TestAssert.cpp
index 44be55f..6e4e794 100644
--- a/src/cppunit/TestAssert.cpp
+++ b/src/cppunit/TestAssert.cpp
@@ -1,19 +1,5 @@
#include <cppunit/TestAssert.h>
-
-#include <math.h>
-
-#if !defined(CPPUNIT_HAVE_ISFINITE)
-
- static inline bool isfinite( double x )
- {
-#if defined(CPPUNIT_HAVE_FINITE)
- return finite( x );
-#else
- return ( x * 0.0 ) == 0.0;
-#endif
- }
-
-#endif
+#include <cppunit/portability/FloatingPoint.h>
CPPUNIT_NS_BEGIN
@@ -30,10 +16,23 @@ assertDoubleEquals( double expected,
msg.addDetail( AdditionalMessage(message) );
bool equal;
- if ( isfinite(expected) && isfinite(actual) )
+ if ( floatingPointIsFinite(expected) && floatingPointIsFinite(actual) )
equal = fabs( expected - actual ) <= delta;
else
- equal = expected == actual;
+ {
+ // If expected or actual is not finite, it may be +inf, -inf or NaN (Not a Number).
+ // Value of +inf or -inf leads to a true equality regardless of delta if both
+ // expected and actual have the same value (infinity sign).
+ // NaN Value should always lead to a failed equality.
+ if ( floatingPointIsUnordered(expected) || floatingPointIsUnordered(actual) )
+ {
+ equal = false; // expected or actual is a NaN
+ }
+ else // ordered values, +inf or -inf comparison
+ {
+ equal = expected == actual;
+ }
+ }
Asserter::failNotEqualIf( !equal,
assertion_traits<double>::toString(expected),
diff --git a/src/cppunit/cppunit.dsp b/src/cppunit/cppunit.dsp
index 7dcffe4..55f4769 100644
--- a/src/cppunit/cppunit.dsp
+++ b/src/cppunit/cppunit.dsp
@@ -247,6 +247,10 @@ SOURCE=..\..\include\cppunit\portability\CppUnitVector.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\cppunit\portability\FloatingPoint.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\cppunit\Portability.h
# End Source File
# Begin Source File