avoid gcc 3.4.3 bug on long double NaN on Irix 6.5
authorEric Blake <ebb9@byu.net>
Fri, 27 Feb 2009 03:18:42 +0000 (20:18 -0700)
committerEric Blake <ebb9@byu.net>
Fri, 27 Feb 2009 03:50:03 +0000 (20:50 -0700)
* tests/nan.h (NaNl): Rewrite as function on Irix, to avoid
compilation bug by using runtime conversion.
* m4/isfinite.m4 (gl_ISFINITE): Likewise.
* m4/isnanl.m4 (gl_FUNC_ISNANL): Likewise.
* modules/ceill-tests (Files): Use nan.h.
* modules/floorl-tests (Files): Likewise.
* modules/frexpl-tests (Files): Likewise.
* modules/isnanl-tests (Files): Likewise.
* modules/ldexpl-tests (Files): Likewise.
* modules/roundl-tests (Files): Likewise.
* modules/truncl-tests (Files): Likewise.
* tests/test-ceill.c (main): Use a working NaN.
* tests/test-floorl.c (main): Likewise.
* tests/test-frexpl.c (main): Likewise.
* tests/test-isnan.c (test_long_double): Likewise.
* tests/test-isnanl.h (main): Likewise.
* tests/test-ldexpl.h (main): Likewise.
* tests/test-roundl.h (main): Likewise.
* tests/test-truncl.h (main): Likewise.
See http://lists.gnu.org/archive/html/bug-gnulib/2009-02/msg00190.html.

Signed-off-by: Eric Blake <ebb9@byu.net>
19 files changed:
ChangeLog
m4/isfinite.m4
m4/isnanl.m4
modules/ceill-tests
modules/floorl-tests
modules/frexpl-tests
modules/isnanl-tests
modules/ldexpl-tests
modules/roundl-tests
modules/truncl-tests
tests/nan.h
tests/test-ceill.c
tests/test-floorl.c
tests/test-frexpl.c
tests/test-isnan.c
tests/test-isnanl.h
tests/test-ldexpl.c
tests/test-roundl.c
tests/test-truncl.c

index 583fa8f13ef01652a5280ab0d12a908296452332..90f91f6cc82c98e0bfa75d5a2a881ec12b4ae4ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
 2009-02-26  Eric Blake  <ebb9@byu.net>
-            Bruno Haible  <bruno@clisp.org>
+
+       avoid gcc 3.4.3 bug on long double NaN on Irix 6.5
+       * tests/nan.h (NaNl): Rewrite as function on Irix, to avoid
+       compilation bug by using runtime conversion.
+       * m4/isfinite.m4 (gl_ISFINITE): Likewise.
+       * m4/isnanl.m4 (gl_FUNC_ISNANL): Likewise.
+       * modules/ceill-tests (Files): Use nan.h.
+       * modules/floorl-tests (Files): Likewise.
+       * modules/frexpl-tests (Files): Likewise.
+       * modules/isnanl-tests (Files): Likewise.
+       * modules/ldexpl-tests (Files): Likewise.
+       * modules/roundl-tests (Files): Likewise.
+       * modules/truncl-tests (Files): Likewise.
+       * tests/test-ceill.c (main): Use a working NaN.
+       * tests/test-floorl.c (main): Likewise.
+       * tests/test-frexpl.c (main): Likewise.
+       * tests/test-isnan.c (test_long_double): Likewise.
+       * tests/test-isnanl.h (main): Likewise.
+       * tests/test-ldexpl.h (main): Likewise.
+       * tests/test-roundl.h (main): Likewise.
+       * tests/test-truncl.h (main): Likewise.
+       See http://lists.gnu.org/archive/html/bug-gnulib/2009-02/msg00190.html.
+
+2009-02-26  Eric Blake  <ebb9@byu.net>
+           Bruno Haible  <bruno@clisp.org>
 
        Work around a *printf bug with %ls on Solaris.
        * m4/printf.m4 (gl_PRINTF_DIRECTIVE_LS): Also test whether, when a
index 055ba8237d714227cb0da32f5c5249e3762d2e1f..019eb9590f52503e01be9fcb951cb53d106bfe46 100644 (file)
@@ -1,4 +1,4 @@
-# isfinite.m4 serial 4
+# isfinite.m4 serial 5
 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -56,6 +56,17 @@ AC_DEFUN([gl_ISFINITEL_WORKS],
   ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
 typedef union { unsigned int word[NWORDS]; long double value; }
         memory_long_double;
+/* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
+   runtime type conversion.  */
+#ifdef __sgi
+static long double NaNl ()
+{
+  double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaNl() (0.0L / 0.0L)
+#endif
 int main ()
 {
   memory_long_double m;
@@ -65,7 +76,7 @@ int main ()
      in the mantissa bits.  The xor operation twiddles a bit that can only be
      a sign bit or a mantissa bit (since the exponent never extends to
      bit 31).  */
-  m.value = 0.0L / 0.0L;
+  m.value = NaNl ();
   m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
   for (i = 0; i < NWORDS; i++)
     m.word[i] |= 1;
index fb63ac45511d55f6f155eb5d099129182cd78a22..e3029f5c913d3bc23c0a74d7d9a237a94fce6b0e 100644 (file)
@@ -1,4 +1,4 @@
-# isnanl.m4 serial 11
+# isnanl.m4 serial 12
 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -133,20 +133,30 @@ AC_DEFUN([gl_FUNC_ISNANL_WORKS],
   ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
 typedef union { unsigned int word[NWORDS]; long double value; }
         memory_long_double;
+/* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
+   runtime type conversion.  */
+#ifdef __sgi
+static long double NaNl ()
+{
+  double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaNl() (0.0L / 0.0L)
+#endif
 int main ()
 {
   memory_long_double m;
   unsigned int i;
 
-  /* gcc-3.4.3 on IRIX 6.5 appears to have a problem with this.  */
-  if (!isnanl (0.0L / 0.0L))
+  if (!isnanl (NaNl ()))
     return 1;
 
   /* The isnanl function should be immune against changes in the sign bit and
      in the mantissa bits.  The xor operation twiddles a bit that can only be
      a sign bit or a mantissa bit (since the exponent never extends to
      bit 31).  */
-  m.value = 0.0L / 0.0L;
+  m.value = NaNl ();
   m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
   for (i = 0; i < NWORDS; i++)
     m.word[i] |= 1;
index 381b3a5ed0060df1777906dd17b9d0212ef10984..ab10141d206f138c8472266fe8bba2c51f6cbda9 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-ceill.c
+tests/nan.h
 
 Depends-on:
 fpucw
index 7aef91d24c9d4c009c23786806c113e89136b33d..ca7c7461fadea1296f475d0d2217282c5e550ab3 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-floorl.c
+tests/nan.h
 
 Depends-on:
 fpucw
index 6291f4eb2424a3ecedc4f18d45a2c1f82602fb0c..f5505b45d95d7dc8992df1555d262d087405c21d 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-frexpl.c
+tests/nan.h
 
 Depends-on:
 fpucw
index 7b4086e6e61d9e48754a9ade655c741c53bca5a7..518420faf1838a5aa5c8e12a274417762cec9ff8 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-isnanl.c
 tests/test-isnanl.h
+tests/nan.h
 
 Depends-on:
 float
index 6c88bfdaceaa97d567860ca8796456ff1f1a81b8..0b1ba0490d6184a792affed5ccb9f6d0a9920cdb 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-ldexpl.c
+tests/nan.h
 
 Depends-on:
 fpucw
index 8e329a5c2149a62cddfac248634d37732c8d7906..442c279c767a1d379e020dbd093a50a7bcc53e70 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-roundl.c
+tests/nan.h
 
 Depends-on:
 fpucw
index 236585475aa79c4129f9dcdc73b03068ae6ad894..7ffc1cde68239fd2ce32e6b425d38ab0e4736f61 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-truncl.c
+tests/nan.h
 
 Depends-on:
 fpucw
index 3bdf6438c26ff363f950e78fe9f7b8090c0126af..8aa8bf002d13bee20ece0aa6c4dea2ba3837422d 100644 (file)
@@ -1,5 +1,5 @@
 /* Macros for not-a-number.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -47,4 +47,14 @@ NaNd ()
 
 /* NaNl () returns a 'long double' not-a-number.  */
 
-#define NaNl() (0.0L / 0.0L)
+/* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
+   runtime type conversion.  */
+#ifdef __sgi
+static long double NaNl ()
+{
+  double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaNl() (0.0L / 0.0L)
+#endif
index d1f0266c5ae3871c5a832bfc03794768c1ec5f86..3d4c9e3e8980ecb3005a52a42d94afea17d4bee1 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "fpucw.h"
 #include "isnanl-nolibm.h"
+#include "nan.h"
 
 #define ASSERT(expr) \
   do                                                                        \
@@ -90,7 +91,7 @@ main ()
   ASSERT (ceill (1.0L / 0.0L) == 1.0L / 0.0L);
   ASSERT (ceill (-1.0L / 0.0L) == -1.0L / 0.0L);
   /* NaNs.  */
-  ASSERT (isnanl (ceill (0.0L / 0.0L)));
+  ASSERT (isnanl (ceill (NaNl ())));
 
   return 0;
 }
index 14979e68dca0e15c2fdbe481bafa0a3bee09bc28..87fea7f86fd0078ff084face6dd5fb3dafd391e0 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "fpucw.h"
 #include "isnanl-nolibm.h"
+#include "nan.h"
 
 #define ASSERT(expr) \
   do                                                                        \
@@ -90,7 +91,7 @@ main ()
   ASSERT (floorl (1.0L / 0.0L) == 1.0L / 0.0L);
   ASSERT (floorl (-1.0L / 0.0L) == -1.0L / 0.0L);
   /* NaNs.  */
-  ASSERT (isnanl (floorl (0.0L / 0.0L)));
+  ASSERT (isnanl (floorl (NaNl ())));
 
   return 0;
 }
index 2b968b8eed59b8ada48b324f22c9a0ca5222b1e3..d4babb88c3c80378a57fbb281819f447f77c1632 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "fpucw.h"
 #include "isnanl-nolibm.h"
+#include "nan.h"
 
 /* Avoid some warnings from "gcc -Wshadow".
    This file doesn't use the exp() function.  */
@@ -95,7 +96,7 @@ main ()
   { /* NaN.  */
     int exp = -9999;
     long double mantissa;
-    x = 0.0L / 0.0L;
+    x = NaNl ();
     mantissa = frexpl (x, &exp);
     ASSERT (isnanl (mantissa));
   }
index 61490176c2f12682c98baed54aebfb04e613f889..9a0856a0e76dfadd73267103f13999dc22c7b6bd 100644 (file)
@@ -163,14 +163,14 @@ test_long_double (void)
   ASSERT (!isnan (1.0L / 0.0L));
   ASSERT (!isnan (-1.0L / 0.0L));
   /* Quiet NaN.  */
-  ASSERT (isnan (0.0L / 0.0L));
+  ASSERT (isnan (NaNl ()));
 
 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
   /* A bit pattern that is different from a Quiet NaN.  With a bit of luck,
      it's a Signalling NaN.  */
   {
     memory_long_double m;
-    m.value = 0.0L / 0.0L;
+    m.value = NaNl ();
 # if LDBL_EXPBIT0_BIT > 0
     m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
 # else
index 37e28579c704f7176f7a60417d230996b376f502..baf04db0db8c55fbd1c6cccf051780a400159dca 100644 (file)
@@ -21,6 +21,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "nan.h"
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
@@ -70,14 +72,14 @@ main ()
   ASSERT (!isnanl (1.0L / 0.0L));
   ASSERT (!isnanl (-1.0L / 0.0L));
   /* Quiet NaN.  */
-  ASSERT (isnanl (0.0L / 0.0L));
+  ASSERT (isnanl (NaNl ()));
 
 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
   /* A bit pattern that is different from a Quiet NaN.  With a bit of luck,
      it's a Signalling NaN.  */
   {
     memory_long_double m;
-    m.value = 0.0L / 0.0L;
+    m.value = NaNl ();
 # if LDBL_EXPBIT0_BIT > 0
     m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
 # else
index 395c00fb09d663e0036f07dfe19dad675854a9e9..5f1fbd99fd6acff8daa4cde3b56a621ac949d5a4 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "fpucw.h"
 #include "isnanl-nolibm.h"
+#include "nan.h"
 
 #define ASSERT(expr) \
   do                                                                        \
@@ -66,7 +67,7 @@ main ()
   BEGIN_LONG_DOUBLE_ROUNDING ();
 
   { /* NaN.  */
-    x = 0.0L / 0.0L;
+    x = NaNl ();
     y = ldexpl (x, 0); ASSERT (isnanl (y));
     y = ldexpl (x, 5); ASSERT (isnanl (y));
     y = ldexpl (x, -5); ASSERT (isnanl (y));
index 51cd1cdd9e30cebbcb54381f1b6ee0f42b64fd0c..ddbf4744417b3a87f0c1a62d7d0e190958dec7ab 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "fpucw.h"
 #include "isnanl-nolibm.h"
+#include "nan.h"
 
 #define ASSERT(expr) \
   do                                                                        \
@@ -97,7 +98,7 @@ main ()
   ASSERT (roundl (1.0 / 0.0L) == 1.0 / 0.0L);
   ASSERT (roundl (-1.0 / 0.0L) == -1.0 / 0.0L);
   /* NaNs.  */
-  ASSERT (isnanl (roundl (0.0L / 0.0L)));
+  ASSERT (isnanl (roundl (NaNl ())));
 
   return 0;
 }
index aad677d6c67a4ef90912202f7445a6fb963c6af8..f8ce551e9c8828ba91e525547169835caf960e29 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "fpucw.h"
 #include "isnanl-nolibm.h"
+#include "nan.h"
 
 #define ASSERT(expr) \
   do                                                                        \
@@ -89,7 +90,7 @@ main ()
   ASSERT (truncl (1.0L / 0.0L) == 1.0L / 0.0L);
   ASSERT (truncl (-1.0L / 0.0L) == -1.0L / 0.0L);
   /* NaNs.  */
-  ASSERT (isnanl (truncl (0.0L / 0.0L)));
+  ASSERT (isnanl (truncl (NaNl ())));
 
   return 0;
 }