Author: sebor
Date: Wed Sep 21 11:45:12 2005
New Revision: 290783

URL: http://svn.apache.org/viewcvs?rev=290783&view=rev
Log:
2005-09-21  Martin Sebor  <[EMAIL PROTECTED]>

        * valcmp.cpp (rw_ldblcmp): Implemented in terms of absolute
        and relative errors instead of naively using memcmp().


Modified:
    incubator/stdcxx/trunk/tests/src/valcmp.cpp

Modified: incubator/stdcxx/trunk/tests/src/valcmp.cpp
URL: 
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/valcmp.cpp?rev=290783&r1=290782&r2=290783&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/valcmp.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/valcmp.cpp Wed Sep 21 11:45:12 2005
@@ -777,6 +777,8 @@
 
 #ifndef _RWSTD_NO_LONG_DOUBLE
 
+#  define Abs(x) ((x) < 0 ? -(x) : (x))
+
 _TEST_EXPORT int
 rw_ldblcmp (long double x, long double y)
 {
@@ -787,7 +789,21 @@
         return 0;
 
     // FIXME: use integer math as in the functions above
-    return memcmp (&x, &y, sizeof x);
+
+    const long double diff = x - y;
+
+    // check absolute error
+    if (Abs (diff) < _RWSTD_LDBL_EPSILON)
+        return 0;
+
+    // check relative error
+    const long double relerr =
+        Abs (x) < Abs (y) ? Abs (diff / y) : Abs (diff / x);
+
+    if (relerr <= 0.0000001L)
+        return 0;
+
+    return x < y ? -1 : +1;
 }
 
 #endif   // _RWSTD_NO_LONG_DOUBLE


Reply via email to