have bootstrap initialize git-merge-changelog if found
[gnulib.git] / tests / test-strtod.c
index 0d1cea1..d99e5fe 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
+#include "isnand-nolibm.h"
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
       if (!(expr))                                                          \
        {                                                                    \
          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+         fflush (stderr);                                                   \
          /* FIXME abort ();*/status = 1;                               \
        }                                                                    \
     }                                                                       \
   while (0)
 
+/* Avoid requiring -lm just for fabs.  */
+#define FABS(d) ((d) < 0.0 ? -(d) : (d))
+
+/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
+   So we use -zero instead.  */
+double zero = 0.0;
+
 int
 main ()
 {
@@ -160,7 +170,7 @@ main ()
     /* FIXME - gnulib's version is rather inaccurate.  It would be
        nice to guarantee an exact result, but for now, we settle for a
        1-ulp error.  */
-    ASSERT (abs (result - 0.5) < DBL_EPSILON);
+    ASSERT (FABS (result - 0.5) < DBL_EPSILON);
     ASSERT (ptr == input + 2);
     ASSERT (errno == 0);
   }
@@ -243,7 +253,7 @@ main ()
     /* FIXME - gnulib's version is rather inaccurate.  It would be
        nice to guarantee an exact result, but for now, we settle for a
        1-ulp error.  */
-    ASSERT (abs (result - 0.5) < DBL_EPSILON);
+    ASSERT (FABS (result - 0.5) < DBL_EPSILON);
     ASSERT (ptr == input + 4);
     ASSERT (errno == 0);
   }
@@ -311,7 +321,7 @@ main ()
     errno = 0;
     result = strtod (input, &ptr);
     ASSERT (result == 0.0);
-    ASSERT (!!signbit (result) == !!signbit (-0.0)); /* IRIX 6.5, OSF/1 4.0 */
+    ASSERT (!!signbit (result) == !!signbit (-zero)); /* IRIX 6.5, OSF/1 4.0 */
     ASSERT (ptr == input + 2);
     ASSERT (errno == 0);
   }
@@ -406,7 +416,7 @@ main ()
     errno = 0;
     result = strtod (input, &ptr);
     ASSERT (result == 0.0);
-    ASSERT (!!signbit (result) == !!signbit (-0.0)); /* MacOS X 10.3, FreeBSD 6.2, IRIX 6.5, OSF/1 4.0 */
+    ASSERT (!!signbit (result) == !!signbit (-zero)); /* MacOS X 10.3, FreeBSD 6.2, IRIX 6.5, OSF/1 4.0 */
     ASSERT (ptr == input + 2);          /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
     ASSERT (errno == 0);
   }
@@ -514,7 +524,7 @@ main ()
     double result;
     errno = 0;
     result = strtod (input, &ptr);
-    ASSERT (0.0 <= result && result <= FLT_MIN);
+    ASSERT (0.0 <= result && result <= DBL_MIN);
     ASSERT (!signbit (result));
     ASSERT (ptr == input + 9);
     ASSERT (errno == ERANGE);
@@ -525,13 +535,13 @@ main ()
     double result;
     errno = 0;
     result = strtod (input, &ptr);
-    ASSERT (-FLT_MIN <= result && result <= 0.0);
+    ASSERT (-DBL_MIN <= result && result <= 0.0);
 #if 0
     /* FIXME - this is glibc bug 5995; POSIX allows returning positive
        0 on negative underflow, even though quality of implementation
        demands preserving the sign.  Disable this test until fixed
        glibc is more prevalent.  */
-    ASSERT (!!signbit (result) == !!signbit (-0.0)); /* glibc-2.3.6, mingw */
+    ASSERT (!!signbit (result) == !!signbit (-zero)); /* glibc-2.3.6, mingw */
 #endif
     ASSERT (ptr == input + 10);
     ASSERT (errno == ERANGE);
@@ -601,8 +611,8 @@ main ()
     result1 = strtod (input, &ptr1);
     result2 = strtod (input + 1, &ptr2);
 #if 1 /* All known CPUs support NaNs.  */
-    ASSERT (isnan (result1));           /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
-    ASSERT (isnan (result2));           /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result1));          /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result2));          /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
 # if 0
     /* Sign bits of NaN is a portability sticking point, not worth
        worrying about.  */
@@ -631,8 +641,8 @@ main ()
     result1 = strtod (input, &ptr1);
     result2 = strtod (input + 1, &ptr2);
 #if 1 /* All known CPUs support NaNs.  */
-    ASSERT (isnan (result1));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
-    ASSERT (isnan (result2));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result1));          /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result2));          /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
     ASSERT (!!signbit (result1) == !!signbit (result2));
     ASSERT (ptr1 == input + 4);         /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 2.5.1, mingw */
     ASSERT (ptr2 == input + 4);         /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 2.5.1, mingw */
@@ -657,8 +667,8 @@ main ()
     result1 = strtod (input, &ptr1);
     result2 = strtod (input + 1, &ptr2);
 #if 1 /* All known CPUs support NaNs.  */
-    ASSERT (isnan (result1));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
-    ASSERT (isnan (result2));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result1));          /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result2));          /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
 # if 0
     /* Sign bits of NaN is a portability sticking point, not worth
        worrying about.  */
@@ -684,7 +694,7 @@ main ()
     errno = 0;
     result = strtod (input, &ptr);
 #if 1 /* All known CPUs support NaNs.  */
-    ASSERT (isnan (result));            /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
     ASSERT (ptr == input + 6);          /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
     ASSERT (errno == 0);
 #else
@@ -707,8 +717,8 @@ main ()
     result1 = strtod (input, &ptr1);
     result2 = strtod (input + 1, &ptr2);
 #if 1 /* All known CPUs support NaNs.  */
-    ASSERT (isnan (result1));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
-    ASSERT (isnan (result2));           /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result1));          /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
+    ASSERT (isnand (result2));          /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
 # if 0
     /* Sign bits of NaN is a portability sticking point, not worth
        worrying about.  */
@@ -900,7 +910,7 @@ main ()
        errno = 0;
        result = strtod (input, &ptr);
        ASSERT (result == 0.0);
-       ASSERT (!!signbit (result) == !!signbit (-0.0)); /* IRIX 6.5, OSF/1 4.0 */
+       ASSERT (!!signbit (result) == !!signbit (-zero)); /* IRIX 6.5, OSF/1 4.0 */
        ASSERT (ptr == input + m);
        ASSERT (errno == 0);
       }
@@ -910,7 +920,7 @@ main ()
   /* Rounding.  */
   /* TODO - is it worth some tests of rounding for typical IEEE corner
      cases, such as .5 ULP rounding up to the smallest denormal and
-     not causing underflow, or FLT_MIN - .5 ULP not causing an
+     not causing underflow, or DBL_MIN - .5 ULP not causing an
      infinite loop?  */
 
   return status;