You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2005/11/12 01:48:00 UTC

svn commit: r332687 - /incubator/stdcxx/trunk/tests/src/valcmp.cpp

Author: sebor
Date: Fri Nov 11 16:47:57 2005
New Revision: 332687

URL: http://svn.apache.org/viewcvs?rev=332687&view=rev
Log:
2005-11-11  Martin Sebor  <se...@roguewave.com>

	* valcmp.cpp (rw_dblcmp): Hacked around a missing 64-bit integer
	type (e.g., when long long support has been disabled).

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=332687&r1=332686&r2=332687&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/valcmp.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/valcmp.cpp Fri Nov 11 16:47:57 2005
@@ -741,6 +741,9 @@
 }
 
 
+#define Abs(x) ((x) < 0 ? -(x) : (x))
+
+
 _TEST_EXPORT int
 rw_dblcmp (double x, double y)
 {
@@ -753,11 +756,32 @@
 #elif _RWSTD_DBL_SIZE == _RWSTD_LLONG_SIZE
     typedef _RWSTD_LONG_LONG IntT;
     const IntT imin = _RWSTD_LLONG_MIN;
-#else
-    // ???
-#  error no integral type of the same size as double exists
 #endif
 
+#if _RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE
+
+    if (x == y)
+        return 0;
+
+    // FIXME: use integer math as in the functions above
+
+    const double diff = x - y;
+
+    // check absolute error
+    if (Abs (diff) < _RWSTD_DBL_EPSILON)
+        return 0;
+
+    // check relative error
+    const double relerr =
+        Abs (x) < Abs (y) ? Abs (diff / y) : Abs (diff / x);
+
+    if (relerr <= 0.0000001)
+        return 0;
+
+    return x < y ? -1 : +1;
+
+#else   // if !(_RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE)
+
     if (x == y)
         return 0;
 
@@ -772,12 +796,13 @@
     const IntT int_diff = x_int - y_int;
 
     return int_diff;
+
+#endif   // _RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE
+
 }
 
 
 #ifndef _RWSTD_NO_LONG_DOUBLE
-
-#  define Abs(x) ((x) < 0 ? -(x) : (x))
 
 _TEST_EXPORT int
 rw_ldblcmp (long double x, long double y)