Override the system isnanf also on IRIX 6.5 with gcc.
authorBruno Haible <bruno@clisp.org>
Sat, 12 Apr 2008 16:33:53 +0000 (18:33 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 12 Apr 2008 16:33:53 +0000 (18:33 +0200)
ChangeLog
m4/isnanf.m4

index 9bbda9e..a85a5e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-12  Bruno Haible  <bruno@clisp.org>
+
+       * m4/isnanf.m4 (gl_ISNANF_WORKS): Add a test for a special NaN.
+       Reported by Nelson H. F. Beebe <beebe@math.utah.edu>.
+
 2008-04-12  Jim Meyering  <meyering@redhat.com>
 
        * m4/math_h.m4 (gl_MATH_H): Fix typos.
index cff2236..1338955 100644 (file)
@@ -1,4 +1,4 @@
-# isnanf.m4 serial 5
+# isnanf.m4 serial 6
 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -47,12 +47,14 @@ AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
     ])
 ])
 
-dnl Test whether isnanf() recognizes a NaN (this fails on IRIX 6.5) and rejects
-dnl Infinity (this fails on Solaris 2.5.1).
+dnl Test whether isnanf() rejects Infinity (this fails on Solaris 2.5.1),
+dnl recognizes a NaN (this fails on IRIX 6.5 with cc), and recognizes a NaN
+dnl with in-memory representation 0x7fbfffff (this fails on IRIX 6.5).
 AC_DEFUN([gl_ISNANF_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION])
   AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works],
     [
       AC_TRY_RUN([
@@ -75,12 +77,34 @@ NaN ()
 #else
 # define NaN() (0.0f / 0.0f)
 #endif
+#define NWORDS \
+  ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+typedef union { unsigned int word[NWORDS]; float value; } memory_float;
 int main()
 {
-  if (!isnanf (NaN ()))
-    return 1;
+  memory_float m;
+
   if (isnanf (1.0f / 0.0f))
     return 1;
+
+  if (!isnanf (NaN ()))
+    return 1;
+
+#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+  /* The isnanf 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.  */
+  if (FLT_EXPBIT0_WORD == 0 && FLT_EXPBIT0_BIT > 0)
+    {
+      m.value = NaN ();
+      /* Set the bits below the exponent to 01111...111.  */
+      m.word[0] &= -1U << FLT_EXPBIT0_BIT;
+      m.word[0] |= 1U << (FLT_EXPBIT0_BIT - 1) - 1;
+      if (!isnanf (m.value))
+        return 1;
+    }
+#endif
+
   return 0;
 }], [gl_cv_func_isnanf_works=yes], [gl_cv_func_isnanf_works=no],
         [case "$host_os" in