changeset 8543:e1fdf02d5cdc

Work around a DEC C compiler bug.
author Bruno Haible <bruno@clisp.org>
date Sun, 25 Mar 2007 19:56:22 +0000
parents 22c2e0092f64
children 245a3653b197
files ChangeLog tests/test-fprintf-posix.h tests/test-frexp.c tests/test-isnan.c tests/test-printf-posix.h tests/test-snprintf-posix.h tests/test-sprintf-posix.h tests/test-vasnprintf-posix.c tests/test-vasprintf-posix.c
diffstat 9 files changed, 128 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2007-03-25  Bruno Haible  <bruno@clisp.org>
 
+	* tests/test-frexp.c (NaN): New function/macro.
+	(main): Use it instead of 0.0 / 0.0.
+	* tests/test-isnan.c (NaN): New function/macro.
+	(main): Use it instead of 0.0 / 0.0.
+	* tests/test-vasnprintf-posix.c (NaN): New function/macro.
+	(test_function): Use it instead of 0.0 / 0.0.
+	* tests/test-vasprintf-posix.c (NaN): New function/macro.
+	(test_function): Use it instead of 0.0 / 0.0.
+	* tests/test-snprintf-posix.h (NaN): New function/macro.
+	(test_function): Use it instead of 0.0 / 0.0.
+	* tests/test-sprintf-posix.h (NaN): New function/macro.
+	(test_function): Use it instead of 0.0 / 0.0.
+	* tests/test-fprintf-posix.h (NaN): New function/macro.
+	(test_function): Use it instead of 0.0 / 0.0.
+	* tests/test-printf-posix.h (NaN): New function/macro.
+	(test_function): Use it instead of 0.0 / 0.0.
+
 	* lib/isnan.c (FUNC): Work around a DEC C compiler bug.
 
 2007-03-25  Bruno Haible  <bruno@clisp.org>
--- a/tests/test-fprintf-posix.h
+++ b/tests/test-fprintf-posix.h
@@ -17,6 +17,18 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (int (*my_fprintf) (FILE *, const char *, ...))
 {
@@ -47,13 +59,13 @@
   my_fprintf (stdout, "%a %d\n", -1.0 / 0.0, 33, 44, 55);
 
   /* NaN.  */
-  my_fprintf (stdout, "%a %d\n", 0.0 / 0.0, 33, 44, 55);
+  my_fprintf (stdout, "%a %d\n", NaN (), 33, 44, 55);
 
   /* FLAG_ZERO with infinite number.  */
   my_fprintf (stdout, "%010a %d\n", 1.0 / 0.0, 33, 44, 55);
 
   /* FLAG_ZERO with NaN.  */
-  my_fprintf (stdout, "%010a %d\n", 0.0 / 0.0, 33, 44, 55);
+  my_fprintf (stdout, "%010a %d\n", NaN (), 33, 44, 55);
 
   /* Test the support of the POSIX/XSI format strings with positions.  */
 
--- a/tests/test-frexp.c
+++ b/tests/test-frexp.c
@@ -26,6 +26,18 @@
 
 #define ASSERT(expr) if (!(expr)) abort ();
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static double
 my_ldexp (double x, int d)
 {
@@ -50,7 +62,7 @@
   { /* NaN.  */
     int exp = -9999;
     double mantissa;
-    x = 0.0 / 0.0;
+    x = NaN ();
     mantissa = frexp (x, &exp);
     ASSERT (mantissa != mantissa);
   }
--- a/tests/test-isnan.c
+++ b/tests/test-isnan.c
@@ -26,6 +26,18 @@
 
 #define ASSERT(expr) if (!(expr)) abort ();
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 int
 main ()
 {
@@ -40,7 +52,7 @@
   ASSERT (!isnan (1.0 / 0.0));
   ASSERT (!isnan (-1.0 / 0.0));
   /* Quiet NaN.  */
-  ASSERT (isnan (0.0 / 0.0));
+  ASSERT (isnan (NaN ()));
 #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
   /* Signalling NaN.  */
   {
@@ -48,7 +60,7 @@
       ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
     typedef union { double value; unsigned int word[NWORDS]; } memory_double;
     memory_double m;
-    m.value = 0.0 / 0.0;
+    m.value = NaN ();
 # if DBL_EXPBIT0_BIT > 0
     m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
 # else
--- a/tests/test-printf-posix.h
+++ b/tests/test-printf-posix.h
@@ -17,6 +17,18 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (int (*my_printf) (const char *, ...))
 {
@@ -47,13 +59,13 @@
   my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55);
 
   /* NaN.  */
-  my_printf ("%a %d\n", 0.0 / 0.0, 33, 44, 55);
+  my_printf ("%a %d\n", NaN (), 33, 44, 55);
 
   /* FLAG_ZERO with infinite number.  */
   my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55);
 
   /* FLAG_ZERO with NaN.  */
-  my_printf ("%010a %d\n", 0.0 / 0.0, 33, 44, 55);
+  my_printf ("%010a %d\n", NaN (), 33, 44, 55);
 
   /* Test the support of the POSIX/XSI format strings with positions.  */
 
--- a/tests/test-snprintf-posix.h
+++ b/tests/test-snprintf-posix.h
@@ -17,6 +17,18 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
 {
@@ -143,7 +155,7 @@
   { /* NaN.  */
     char result[100];
     int retval =
-      my_snprintf (result, sizeof (result), "%a %d", 0.0 / 0.0, 33, 44, 55);
+      my_snprintf (result, sizeof (result), "%a %d", NaN (), 33, 44, 55);
     ASSERT (strcmp (result, "nan 33") == 0);
     ASSERT (retval == strlen (result));
   }
@@ -336,7 +348,7 @@
   { /* FLAG_ZERO with NaN.  */
     char result[100];
     int retval =
-      my_snprintf (result, sizeof (result), "%010a %d", 0.0 / 0.0, 33, 44, 55);
+      my_snprintf (result, sizeof (result), "%010a %d", NaN (), 33, 44, 55);
     ASSERT (strcmp (result, "       nan 33") == 0);
     ASSERT (retval == strlen (result));
   }
--- a/tests/test-sprintf-posix.h
+++ b/tests/test-sprintf-posix.h
@@ -17,6 +17,18 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (int (*my_sprintf) (char *, const char *, ...))
 {
@@ -129,7 +141,7 @@
   { /* NaN.  */
     char result[1000];
     int retval =
-      my_sprintf (result, "%a %d", 0.0 / 0.0, 33, 44, 55);
+      my_sprintf (result, "%a %d", NaN (), 33, 44, 55);
     ASSERT (strcmp (result, "nan 33") == 0);
     ASSERT (retval == strlen (result));
   }
@@ -322,7 +334,7 @@
   { /* FLAG_ZERO with NaN.  */
     char result[1000];
     int retval =
-      my_sprintf (result, "%010a %d", 0.0 / 0.0, 33, 44, 55);
+      my_sprintf (result, "%010a %d", NaN (), 33, 44, 55);
     ASSERT (strcmp (result, "       nan 33") == 0);
     ASSERT (retval == strlen (result));
   }
--- a/tests/test-vasnprintf-posix.c
+++ b/tests/test-vasnprintf-posix.c
@@ -31,6 +31,18 @@
 
 #define ASSERT(expr) if (!(expr)) abort ();
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
 {
@@ -183,7 +195,7 @@
   { /* NaN.  */
     size_t length;
     char *result =
-      my_asnprintf (NULL, &length, "%a %d", 0.0 / 0.0, 33, 44, 55);
+      my_asnprintf (NULL, &length, "%a %d", NaN (), 33, 44, 55);
     ASSERT (result != NULL);
     ASSERT (strcmp (result, "nan 33") == 0);
     ASSERT (length == strlen (result));
@@ -412,7 +424,7 @@
   { /* FLAG_ZERO with NaN.  */
     size_t length;
     char *result =
-      my_asnprintf (NULL, &length, "%010a %d", 0.0 / 0.0, 33, 44, 55);
+      my_asnprintf (NULL, &length, "%010a %d", NaN (), 33, 44, 55);
     ASSERT (result != NULL);
     ASSERT (strcmp (result, "       nan 33") == 0);
     ASSERT (length == strlen (result));
--- a/tests/test-vasprintf-posix.c
+++ b/tests/test-vasprintf-posix.c
@@ -31,6 +31,18 @@
 
 #define ASSERT(expr) if (!(expr)) abort ();
 
+/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
+#ifdef __DECC
+static double
+NaN ()
+{
+  static double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaN() (0.0 / 0.0)
+#endif
+
 static void
 test_function (int (*my_asprintf) (char **, const char *, ...))
 {
@@ -164,7 +176,7 @@
   { /* NaN.  */
     char *result;
     int retval =
-      my_asprintf (&result, "%a %d", 0.0 / 0.0, 33, 44, 55);
+      my_asprintf (&result, "%a %d", NaN (), 33, 44, 55);
     ASSERT (result != NULL);
     ASSERT (strcmp (result, "nan 33") == 0);
     ASSERT (retval == strlen (result));
@@ -393,7 +405,7 @@
   { /* FLAG_ZERO with NaN.  */
     char *result;
     int retval =
-      my_asprintf (&result, "%010a %d", 0.0 / 0.0, 33, 44, 55);
+      my_asprintf (&result, "%010a %d", NaN (), 33, 44, 55);
     ASSERT (result != NULL);
     ASSERT (strcmp (result, "       nan 33") == 0);
     ASSERT (retval == strlen (result));