changeset 8423:5fc4383618f0

Work around bug regarding initializers in SunPRO C and Compaq C compilers.
author Bruno Haible <bruno@clisp.org>
date Sun, 11 Mar 2007 22:40:52 +0000
parents f968c473e8b7
children ec3450ce9889
files ChangeLog lib/isnan.c
diffstat 2 files changed, 27 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-03-11  Bruno Haible  <bruno@clisp.org>
+
+	* lib/isnan.c (rpl_isnan, rpl_isnanl): Work around bug regarding
+	initializers in SunPRO C and Compaq C compilers.
+
 2007-03-11  Bruno Haible  <bruno@clisp.org>
 
 	* lib/gl_array_oset.c (gl_array_iterator_next): Make pointer
--- a/lib/isnan.c
+++ b/lib/isnan.c
@@ -58,21 +58,32 @@
 #ifdef KNOWN_EXPBIT0_LOCATION
   /* Be careful to not do any floating-point operation on x, such as x == x,
      because x may be a signaling NaN.  */
+# if defined __SUNPRO_C || defined __DECC
+  /* The Sun C 5.0 compilers and the Compaq (ex-DEC) 6.4 compilers don't
+     recognize the initializers as constant expressions.  */
+  memory_double nan;
+  DOUBLE plus_inf = L_(1.0) / L_(0.0);
+  DOUBLE minus_inf = -L_(1.0) / L_(0.0);
+  nan.value = L_(0.0) / L_(0.0);
+# else
   static memory_double nan = { L_(0.0) / L_(0.0) };
   static DOUBLE plus_inf = L_(1.0) / L_(0.0);
   static DOUBLE minus_inf = -L_(1.0) / L_(0.0);
-  memory_double m;
+# endif
+  {
+    memory_double m;
 
-  /* A NaN can be recognized through its exponent.  But exclude +Infinity and
-     -Infinity, which have the same exponent.  */
-  m.value = x;
-  if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
-       & (EXP_MASK << EXPBIT0_BIT))
-      == 0)
-    return (memcmp (&m.value, &plus_inf, sizeof (DOUBLE)) != 0
-	    && memcmp (&m.value, &minus_inf, sizeof (DOUBLE)) != 0);
-  else
-    return 0;
+    /* A NaN can be recognized through its exponent.  But exclude +Infinity and
+       -Infinity, which have the same exponent.  */
+    m.value = x;
+    if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
+	 & (EXP_MASK << EXPBIT0_BIT))
+	== 0)
+      return (memcmp (&m.value, &plus_inf, sizeof (DOUBLE)) != 0
+	      && memcmp (&m.value, &minus_inf, sizeof (DOUBLE)) != 0);
+    else
+      return 0;
+  }
 #else
   /* The configuration did not find sufficient information.  Give up about
      the signaling NaNs, handle only the quiet NaNs.  */