Work around bug regarding initializers in SunPRO C and Compaq C compilers.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2007 22:40:52 +0000 (22:40 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2007 22:40:52 +0000 (22:40 +0000)
ChangeLog
lib/isnan.c

index 85d4d68..f3ea301 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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
        decrementing code ANSI C compliant.
 
index ce9e8ea..beeb98a 100644 (file)
@@ -58,21 +58,32 @@ FUNC (DOUBLE x)
 #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.  */