]> Savannah Git Hosting - gnulib.git/commitdiff
tests: Refactor functions for signalling NaNs.
authorBruno Haible <bruno@clisp.org>
Mon, 9 Oct 2023 09:04:44 +0000 (11:04 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 9 Oct 2023 09:06:29 +0000 (11:06 +0200)
* tests/snan.h: New file, based on tests/test-isnanf.h,
tests/test-isnand.h, tests/test-isnanl.h.
* tests/test-isfinite.c: Include snan.h.
(test_isfinitef, test_isfinited, test_isfinitel): Simplify.
* tests/test-isinf.c: Include snan.h.
(test_isinff, test_isinfd, test_isinfl): Simplify.
* tests/test-isnan.c: Include snan.h.
(test_float, test_double, test_long_double): Simplify.
* tests/test-isnanf.h: Include snan.h.
(main): Simplify.
* tests/test-isnand.h: Include snan.h.
(main): Simplify.
* tests/test-isnanl.h: Include snan.h.
(main): Simplify.
* tests/test-signbit.c: Include snan.h.
(test_signbitf, test_signbitd, test_signbitl): Simplify.
* tests/test-stdio.c: Include qnan.h, snan.h instead of nan.h.
(main): Test quiet NaNs always. Also test a signalling NaN.
* modules/isfinite-tests (Files): Add tests/nan.h, tests/snan.h.
* modules/isinf-tests (Files): Likewise.
* modules/isnan-tests (Files): Add tests/snan.h.
* modules/isnanf-tests (Files): Likewise.
* modules/isnanf-nolibm-tests (Files): Likewise.
* modules/isnand-tests (Files): Likewise.
* modules/isnand-nolibm-tests (Files): Likewise.
* modules/isnanl-tests (Files): Likewise.
* modules/isnanl-nolibm-tests (Files): Likewise.
* modules/signbit-tests (Files): Likewise.
* modules/stdio-tests (Files): Add tests/qnan.h, tests/snan.h.

21 files changed:
ChangeLog
modules/isfinite-tests
modules/isinf-tests
modules/isnan-tests
modules/isnand-nolibm-tests
modules/isnand-tests
modules/isnanf-nolibm-tests
modules/isnanf-tests
modules/isnanl-nolibm-tests
modules/isnanl-tests
modules/signbit-tests
modules/stdio-tests
tests/snan.h [new file with mode: 0644]
tests/test-isfinite.c
tests/test-isinf.c
tests/test-isnan.c
tests/test-isnand.h
tests/test-isnanf.h
tests/test-isnanl.h
tests/test-signbit.c
tests/test-stdio.c

index bcd840abb4b5a9a8487e2d3d1eb1c5e3998bd656..ef036d1585f02a99726035fb3a60f473d591b60a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2023-10-09  Bruno Haible  <bruno@clisp.org>
+
+       tests: Refactor functions for signalling NaNs.
+       * tests/snan.h: New file, based on tests/test-isnanf.h,
+       tests/test-isnand.h, tests/test-isnanl.h.
+       * tests/test-isfinite.c: Include snan.h.
+       (test_isfinitef, test_isfinited, test_isfinitel): Simplify.
+       * tests/test-isinf.c: Include snan.h.
+       (test_isinff, test_isinfd, test_isinfl): Simplify.
+       * tests/test-isnan.c: Include snan.h.
+       (test_float, test_double, test_long_double): Simplify.
+       * tests/test-isnanf.h: Include snan.h.
+       (main): Simplify.
+       * tests/test-isnand.h: Include snan.h.
+       (main): Simplify.
+       * tests/test-isnanl.h: Include snan.h.
+       (main): Simplify.
+       * tests/test-signbit.c: Include snan.h.
+       (test_signbitf, test_signbitd, test_signbitl): Simplify.
+       * tests/test-stdio.c: Include qnan.h, snan.h instead of nan.h.
+       (main): Test quiet NaNs always. Also test a signalling NaN.
+       * modules/isfinite-tests (Files): Add tests/nan.h, tests/snan.h.
+       * modules/isinf-tests (Files): Likewise.
+       * modules/isnan-tests (Files): Add tests/snan.h.
+       * modules/isnanf-tests (Files): Likewise.
+       * modules/isnanf-nolibm-tests (Files): Likewise.
+       * modules/isnand-tests (Files): Likewise.
+       * modules/isnand-nolibm-tests (Files): Likewise.
+       * modules/isnanl-tests (Files): Likewise.
+       * modules/isnanl-nolibm-tests (Files): Likewise.
+       * modules/signbit-tests (Files): Likewise.
+       * modules/stdio-tests (Files): Add tests/qnan.h, tests/snan.h.
+
 2023-10-08  Bruno Haible  <bruno@clisp.org>
 
        isfinite: Work around a bug with 'long double' in glibc 2.5/ia64.
index 56207be0277b95c3b9078cb6595c339c14dd9e2e..bf7964648b70c164a64c50f7fee96c0de8f9674f 100644 (file)
@@ -1,6 +1,8 @@
 Files:
 tests/test-isfinite.c
 tests/infinity.h
+tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentf.m4
 m4/exponentd.m4
index 02719fe601fb6128aa8a17bbecd26ce64c08a4cd..fb958d74eabacc30e207f55ea0cb212adff9d636 100644 (file)
@@ -1,6 +1,8 @@
 Files:
 tests/test-isinf.c
 tests/infinity.h
+tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentf.m4
 m4/exponentd.m4
index c794455c5be082d9f9f25ed577ec0d8b7fc9c68b..06ebb721563784288cc198cd16720535bee3106a 100644 (file)
@@ -3,6 +3,7 @@ tests/test-isnan.c
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentf.m4
 m4/exponentd.m4
index 7b74b0b7ed1805a1eb9756d41b328a69e22111a8..c8d92f3a75ccc7d3c1f5b2a6450a570d3784232a 100644 (file)
@@ -4,6 +4,7 @@ tests/test-isnand.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentd.m4
 
index fb3fc494c9af0d3c48ff4ee32cef3906e3334631..30a2c6f9e6b328fdbfb09d8d7e3fbb75c26da7ef 100644 (file)
@@ -4,6 +4,7 @@ tests/test-isnand.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentd.m4
 
index 4635edd9a50e46d27663b064254bf191c0aa4bed..acd8bd34bcac68d6534cc4ff0fce13b6165cdbcd 100644 (file)
@@ -4,6 +4,7 @@ tests/test-isnanf.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentf.m4
 
index 1566695546d56046e04b38c6bffc77a0d0f986c1..c094c02a37b0a861462d09df7fe866ca5740a448 100644 (file)
@@ -4,6 +4,7 @@ tests/test-isnanf.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentf.m4
 
index 927ad693883ad631c23aa731c964446bb3ca7fca..58a0f51fa17500f6d1c048a104c36a521785efd7 100644 (file)
@@ -4,6 +4,7 @@ tests/test-isnanl.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentl.m4
 
index b00e5d591091649c0cef267b74594680f0a96967..5a2d880c3fcbf83ca78472b107eaad6f944a2b31 100644 (file)
@@ -4,6 +4,7 @@ tests/test-isnanl.h
 tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
+tests/snan.h
 tests/macros.h
 m4/exponentl.m4
 
index 9465de790bcf254dd9d2ef504114ee140e9f3036..3b3ef9b6b6290a1f0b8075f501db212efd888a37 100644 (file)
@@ -4,6 +4,7 @@ tests/minus-zero.h
 tests/infinity.h
 tests/nan.h
 tests/qnan.h
+tests/snan.h
 tests/macros.h
 m4/exponentf.m4
 m4/exponentd.m4
index 52b753e2f7f8a5a3d32e937f4c0de54754ac72b9..84199d5aa32715e3989417c22d12a6e3b3a3a9d4 100644 (file)
@@ -1,6 +1,8 @@
 Files:
 tests/test-stdio.c
 tests/nan.h
+tests/qnan.h
+tests/snan.h
 tests/macros.h
 m4/exponentd.m4
 
diff --git a/tests/snan.h b/tests/snan.h
new file mode 100644 (file)
index 0000000..e877000
--- /dev/null
@@ -0,0 +1,120 @@
+/* Macros for signalling not-a-number.
+   Copyright (C) 2007-2023 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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <float.h>
+#include <limits.h>
+#include <math.h>
+
+#include "nan.h"
+
+
+#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+
+# define HAVE_SNANF 1
+
+/* Returns a signalling 'float' NaN.  */
+_GL_UNUSED static float
+SNaNf ()
+{
+  #define NWORDS \
+    ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { float value; unsigned int word[NWORDS]; } memory_float;
+  memory_float m;
+  m.value = NaNf ();
+ #if FLT_EXPBIT0_BIT > 0
+    m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
+ #else
+    m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
+      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
+ #endif
+  if (FLT_EXPBIT0_WORD < NWORDS / 2)
+    m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
+  else
+    m.word[0] |= (unsigned int) 1;
+  #undef NWORDS
+  return m.value;
+}
+
+#endif
+
+
+#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+
+# define HAVE_SNAND 1
+
+/* Returns a signalling 'double' NaN.  */
+_GL_UNUSED static double
+SNaNd ()
+{
+  #define NWORDS \
+    ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { double value; unsigned int word[NWORDS]; } memory_double;
+  memory_double m;
+  m.value = NaNd ();
+  #if DBL_EXPBIT0_BIT > 0
+    m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
+  #else
+    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
+      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
+  #endif
+  m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
+    |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
+  #undef NWORDS
+  return m.value;
+}
+
+#endif
+
+
+#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
+
+# define HAVE_SNANL 1
+
+/* Returns a signalling 'long double' NaN.  */
+_GL_UNUSED static long double
+SNaNl ()
+{
+  /* A bit pattern that is different from a Quiet NaN.  With a bit of luck,
+     it's a Signalling NaN.  */
+  #define NWORDS \
+    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { unsigned int word[NWORDS]; long double value; }
+          memory_long_double;
+  memory_long_double m;
+  m.value = NaNl ();
+  #if defined __powerpc__ && LDBL_MANT_DIG == 106
+    /* This is PowerPC "double double", a pair of two doubles.  Inf and NaN are
+       represented as the corresponding 64-bit IEEE values in the first double;
+       the second is ignored.  Manipulate only the first double.  */
+    #define HNWORDS \
+      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  #else
+    #define HNWORDS NWORDS
+  #endif
+  #if LDBL_EXPBIT0_BIT > 0
+    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
+  #else
+    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)]
+      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
+  #endif
+  m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)]
+    |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
+  #undef HNWORDS
+  #undef NWORDS
+  return m.value;
+}
+
+#endif
index edb5f43327ce612d3409cb64d77fd6b1c64870d4..3c6da8d1283cf0aa12e21b0708468e5036f17f0d 100644 (file)
@@ -30,6 +30,7 @@
 #include <limits.h>
 
 #include "infinity.h"
+#include "snan.h"
 #include "macros.h"
 
 float zerof = 0.0f;
@@ -56,27 +57,9 @@ test_isfinitef ()
   ASSERT (!isfinite (- Infinityf ()));
   /* Quiet NaN.  */
   ASSERT (!isfinite (zerof / zerof));
-#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+#if HAVE_SNANF
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { float value; unsigned int word[NWORDS]; } memory_float;
-    memory_float m;
-    m.value = zerof / zerof;
-# if FLT_EXPBIT0_BIT > 0
-    m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
-# else
-    m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    if (FLT_EXPBIT0_WORD < NWORDS / 2)
-      m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
-    else
-      m.word[0] |= (unsigned int) 1;
-    ASSERT (!isfinite (m.value));
-    #undef NWORDS
-  }
+  ASSERT (!isfinite (SNaNf ()));
 #endif
 }
 
@@ -100,36 +83,15 @@ test_isfinited ()
   ASSERT (!isfinite (- Infinityd ()));
   /* Quiet NaN.  */
   ASSERT (!isfinite (zerod / zerod));
-#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+#if HAVE_SNAND
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { double value; unsigned int word[NWORDS]; } memory_double;
-    memory_double m;
-    m.value = zerod / zerod;
-# if DBL_EXPBIT0_BIT > 0
-    m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
-# else
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
-    ASSERT (!isfinite (m.value));
-    #undef NWORDS
-  }
+  ASSERT (!isfinite (SNaNd ()));
 #endif
 }
 
 static void
 test_isfinitel ()
 {
-  #define NWORDS \
-    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-  typedef union { unsigned int word[NWORDS]; long double value; }
-          memory_long_double;
-
   /* Zero. */
   ASSERT (isfinite (0.0L));
   /* Subnormal values. */
@@ -147,35 +109,16 @@ test_isfinitel ()
   ASSERT (!isfinite (- Infinityl ()));
   /* Quiet NaN.  */
   ASSERT (!isfinite (zerol / zerol));
-
-#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.  */
-  {
-#if defined __powerpc__ && LDBL_MANT_DIG == 106
-    /* This is PowerPC "double double", a pair of two doubles.  Inf and Nan are
-       represented as the corresponding 64-bit IEEE values in the first double;
-       the second is ignored.  Manipulate only the first double.  */
-    #undef NWORDS
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-#endif
-
-    memory_long_double m;
-    m.value = zerol / zerol;
-# if LDBL_EXPBIT0_BIT > 0
-    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
-# else
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
-    ASSERT (!isfinite (m.value));
-  }
+#if HAVE_SNANL
+  /* Signalling NaN.  */
+  ASSERT (!isfinite (SNaNl ()));
 #endif
 
 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  #define NWORDS \
+    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { unsigned int word[NWORDS]; long double value; }
+          memory_long_double;
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
@@ -225,9 +168,8 @@ test_isfinitel ()
       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
     ASSERT (isfinite (x.value) || !isfinite (x.value));
   }
-#endif
-
   #undef NWORDS
+#endif
 }
 
 int
index f1bca0ce1059063ae304e844446ab66ca41b5af2..d3e435b3b24635040241c1f3e73848d551ec2e0b 100644 (file)
@@ -30,6 +30,7 @@
 #include <limits.h>
 
 #include "infinity.h"
+#include "snan.h"
 #include "macros.h"
 
 float zerof = 0.0f;
@@ -58,27 +59,9 @@ test_isinff ()
   ASSERT (isinf (- Infinityf ()));
   /* Quiet NaN.  */
   ASSERT (!isinf (zerof / zerof));
-#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+#if HAVE_SNANF
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { float value; unsigned int word[NWORDS]; } memory_float;
-    memory_float m;
-    m.value = zerof / zerof;
-# if FLT_EXPBIT0_BIT > 0
-    m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
-# else
-    m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    if (FLT_EXPBIT0_WORD < NWORDS / 2)
-      m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
-    else
-      m.word[0] |= (unsigned int) 1;
-    ASSERT (!isinf (m.value));
-    #undef NWORDS
-  }
+  ASSERT (!isinf (SNaNf ()));
 #endif
 }
 
@@ -104,36 +87,15 @@ test_isinfd ()
   ASSERT (isinf (- Infinityd ()));
   /* Quiet NaN.  */
   ASSERT (!isinf (zerod / zerod));
-#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+#if HAVE_SNAND
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { double value; unsigned int word[NWORDS]; } memory_double;
-    memory_double m;
-    m.value = zerod / zerod;
-# if DBL_EXPBIT0_BIT > 0
-    m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
-# else
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
-    ASSERT (!isinf (m.value));
-    #undef NWORDS
-  }
+  ASSERT (!isinf (SNaNd ()));
 #endif
 }
 
 static void
 test_isinfl ()
 {
-  #define NWORDS \
-    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-  typedef union { unsigned int word[NWORDS]; long double value; }
-          memory_long_double;
-
   /* Zero. */
   ASSERT (!isinf (0.0L));
   /* Subnormal values. */
@@ -153,35 +115,16 @@ test_isinfl ()
   ASSERT (isinf (- Infinityl ()));
   /* Quiet NaN.  */
   ASSERT (!isinf (zerol / zerol));
-
-#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.  */
-  {
-#if defined __powerpc__ && LDBL_MANT_DIG == 106
-    /* This is PowerPC "double double", a pair of two doubles.  Inf and Nan are
-       represented as the corresponding 64-bit IEEE values in the first double;
-       the second is ignored.  Manipulate only the first double.  */
-    #undef NWORDS
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-#endif
-
-    memory_long_double m;
-    m.value = zerol / zerol;
-# if LDBL_EXPBIT0_BIT > 0
-    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
-# else
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
-    ASSERT (!isinf (m.value));
-  }
+#if HAVE_SNANL
+  /* Signalling NaN.  */
+  ASSERT (!isinf (SNaNl ()));
 #endif
 
 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  #define NWORDS \
+    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { unsigned int word[NWORDS]; long double value; }
+          memory_long_double;
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
@@ -231,9 +174,8 @@ test_isinfl ()
       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
     ASSERT (isinf (x.value) || !isinf (x.value));
   }
-#endif
-
   #undef NWORDS
+#endif
 }
 
 int
index 062c4cad24cf5d5ff880682d14bd4c567d8caf9a..2d744596f5da080aa7df5a04428aecab810a194c 100644 (file)
@@ -32,6 +32,7 @@
 #include "minus-zero.h"
 #include "infinity.h"
 #include "nan.h"
+#include "snan.h"
 #include "macros.h"
 
 static void
@@ -51,26 +52,9 @@ test_float (void)
   ASSERT (!isnan (- Infinityf ()));
   /* Quiet NaN.  */
   ASSERT (isnan (NaNf ()));
-#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+#if HAVE_SNANF
   /* Signalling NaN.  */
-  {
-    #define NWORDSF \
-      ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { float value; unsigned int word[NWORDSF]; } memory_float;
-    memory_float m;
-    m.value = NaNf ();
-# if FLT_EXPBIT0_BIT > 0
-    m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
-# else
-    m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDSF / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    if (FLT_EXPBIT0_WORD < NWORDSF / 2)
-      m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
-    else
-      m.word[0] |= (unsigned int) 1;
-    ASSERT (isnan (m.value));
-  }
+  ASSERT (isnan (SNaNf ()));
 #endif
 }
 
@@ -91,35 +75,15 @@ test_double (void)
   ASSERT (!isnan (- Infinityd ()));
   /* Quiet NaN.  */
   ASSERT (isnan (NaNd ()));
-#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+#if HAVE_SNAND
   /* Signalling NaN.  */
-  {
-    #define NWORDSD \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { double value; unsigned int word[NWORDSD]; } memory_double;
-    memory_double m;
-    m.value = NaNd ();
-# if DBL_EXPBIT0_BIT > 0
-    m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
-# else
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDSD / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDSD / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
-    ASSERT (isnan (m.value));
-  }
+  ASSERT (isnan (SNaNd ()));
 #endif
 }
 
 static void
 test_long_double (void)
 {
-  #define NWORDSL \
-    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-  typedef union { unsigned int word[NWORDSL]; long double value; }
-          memory_long_double;
-
   /* Finite values.  */
   ASSERT (!isnan (3.141L));
   ASSERT (!isnan (3.141e30L));
@@ -134,35 +98,16 @@ test_long_double (void)
   ASSERT (!isnan (- Infinityl ()));
   /* Quiet NaN.  */
   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.  */
-  {
-#if defined __powerpc__ && LDBL_MANT_DIG == 106
-    /* This is PowerPC "double double", a pair of two doubles.  Inf and Nan are
-       represented as the corresponding 64-bit IEEE values in the first double;
-       the second is ignored.  Manipulate only the first double.  */
-    #undef NWORDSL
-    #define NWORDSL \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-#endif
-
-    memory_long_double m;
-    m.value = NaNl ();
-# if LDBL_EXPBIT0_BIT > 0
-    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
-# else
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDSL / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDSL / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
-    ASSERT (isnan (m.value));
-  }
+#if HAVE_SNANL
+  /* Signalling NaN.  */
+  ASSERT (isnan (SNaNl ()));
 #endif
 
 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  #define NWORDS \
+    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { unsigned int word[NWORDS]; long double value; }
+          memory_long_double;
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
@@ -212,6 +157,7 @@ test_long_double (void)
       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
     ASSERT (isnan (x.value) || !isnan (x.value));
   }
+  #undef NWORDS
 #endif
 }
 
index 2d89ce1aedbf76a768f083de85927e698b9d005a..e52756efd51b06ba0891c1d05517773e377ac64f 100644 (file)
@@ -21,6 +21,7 @@
 #include "minus-zero.h"
 #include "infinity.h"
 #include "nan.h"
+#include "snan.h"
 #include "macros.h"
 
 int
@@ -40,24 +41,9 @@ main ()
   ASSERT (!isnand (- Infinityd ()));
   /* Quiet NaN.  */
   ASSERT (isnand (NaNd ()));
-#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+#if HAVE_SNAND
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { double value; unsigned int word[NWORDS]; } memory_double;
-    memory_double m;
-    m.value = NaNd ();
-# if DBL_EXPBIT0_BIT > 0
-    m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
-# else
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
-    ASSERT (isnand (m.value));
-  }
+  ASSERT (isnand (SNaNd ()));
 #endif
   return 0;
 }
index aa2a72c12856758996de346da88a3c6c6a5eeeb7..0cd78350a6a12ae2845f526b775c74652c74a0ee 100644 (file)
@@ -21,6 +21,7 @@
 #include "minus-zero.h"
 #include "infinity.h"
 #include "nan.h"
+#include "snan.h"
 #include "macros.h"
 
 int
@@ -40,26 +41,9 @@ main ()
   ASSERT (!isnanf (- Infinityf ()));
   /* Quiet NaN.  */
   ASSERT (isnanf (NaNf ()));
-#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+#if HAVE_SNANF
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { float value; unsigned int word[NWORDS]; } memory_float;
-    memory_float m;
-    m.value = NaNf ();
-# if FLT_EXPBIT0_BIT > 0
-    m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
-# else
-    m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    if (FLT_EXPBIT0_WORD < NWORDS / 2)
-      m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
-    else
-      m.word[0] |= (unsigned int) 1;
-    ASSERT (isnanf (m.value));
-  }
+  ASSERT (isnanf (SNaNf ()));
 #endif
   return 0;
 }
index 4ca408bf9151031a833af9b1ace02ef7111dd99d..fa7d87b3cdc8760449abe31ad816867277564b61 100644 (file)
 #include "minus-zero.h"
 #include "infinity.h"
 #include "nan.h"
+#include "snan.h"
 #include "macros.h"
 
 int
 main ()
 {
-  #define NWORDS \
-    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-  typedef union { unsigned int word[NWORDS]; long double value; }
-          memory_long_double;
-
   /* Finite values.  */
   ASSERT (!isnanl (3.141L));
   ASSERT (!isnanl (3.141e30L));
@@ -46,35 +42,16 @@ main ()
   ASSERT (!isnanl (- Infinityl ()));
   /* Quiet NaN.  */
   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.  */
-  {
-#if defined __powerpc__ && LDBL_MANT_DIG == 106
-    /* This is PowerPC "double double", a pair of two doubles.  Inf and Nan are
-       represented as the corresponding 64-bit IEEE values in the first double;
-       the second is ignored.  Manipulate only the first double.  */
-    #undef NWORDS
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-#endif
-
-    memory_long_double m;
-    m.value = NaNl ();
-# if LDBL_EXPBIT0_BIT > 0
-    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
-# else
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
-    ASSERT (isnanl (m.value));
-  }
+#if HAVE_SNANL
+  /* Signalling NaN.  */
+  ASSERT (isnanl (SNaNl ()));
 #endif
 
 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  #define NWORDS \
+    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+  typedef union { unsigned int word[NWORDS]; long double value; }
+          memory_long_double;
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
@@ -124,6 +101,7 @@ main ()
       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
     ASSERT (isnanl (x.value) || !isnanl (x.value));
   }
+  #undef NWORDS
 #endif
 
   return 0;
index 2c1daccef286ab475c5ddd0643e6230930a70d24..f89fdf6d0507d51faa3a8f1e157c5b7e10551ee2 100644 (file)
@@ -31,6 +31,7 @@
 #include "minus-zero.h"
 #include "infinity.h"
 #include "qnan.h"
+#include "snan.h"
 #include "macros.h"
 
 float zerof = 0.0f;
@@ -59,27 +60,9 @@ test_signbitf ()
   /* Quiet NaN.  */
   ASSERT (!signbit (positive_NaNf ()));
   ASSERT (signbit (negative_NaNf ()));
-#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+#if HAVE_SNANF
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { float value; unsigned int word[NWORDS]; } memory_float;
-    memory_float m;
-    m.value = zerof / zerof;
-# if FLT_EXPBIT0_BIT > 0
-    m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
-# else
-    m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    if (FLT_EXPBIT0_WORD < NWORDS / 2)
-      m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
-    else
-      m.word[0] |= (unsigned int) 1;
-    (void) signbit (m.value);
-    #undef NWORDS
-  }
+  (void) signbit (SNaNf ());
 #endif
 }
 
@@ -105,25 +88,9 @@ test_signbitd ()
   /* Quiet NaN.  */
   ASSERT (!signbit (positive_NaNd ()));
   ASSERT (signbit (negative_NaNd ()));
-#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+#if HAVE_SNAND
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { double value; unsigned int word[NWORDS]; } memory_double;
-    memory_double m;
-    m.value = zerod / zerod;
-# if DBL_EXPBIT0_BIT > 0
-    m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
-# else
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
-    (void) signbit (m.value);
-    #undef NWORDS
-  }
+  (void) signbit (SNaNd ());
 #endif
 }
 
@@ -149,35 +116,9 @@ test_signbitl ()
   /* Quiet NaN.  */
   ASSERT (!signbit (positive_NaNl ()));
   ASSERT (signbit (negative_NaNl ()));
-#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
+#if HAVE_SNANL
   /* Signalling NaN.  */
-  {
-    #define NWORDS \
-      ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-    typedef union { long double value; unsigned int word[NWORDS]; } memory_long_double;
-
-#if defined __powerpc__ && LDBL_MANT_DIG == 106
-    /* This is PowerPC "double double", a pair of two doubles.  Inf and Nan are
-       represented as the corresponding 64-bit IEEE values in the first double;
-       the second is ignored.  Manipulate only the first double.  */
-    #undef NWORDS
-    #define NWORDS \
-      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-#endif
-
-    memory_long_double m;
-    m.value = zerol / zerol;
-# if LDBL_EXPBIT0_BIT > 0
-    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
-# else
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
-    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
-      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
-    (void) signbit (m.value);
-    #undef NWORDS
-  }
+  (void) signbit (SNaNl ());
 #endif
 }
 
index 9794f4d856580ca5ff3bef41878d5c735c641014..cc442501500a78b1376378d84199a1011c4a782f 100644 (file)
@@ -39,12 +39,25 @@ va_list t5;
 
 #include <string.h>
 
-#include "nan.h"
+#include "qnan.h"
+#include "snan.h"
 #include "macros.h"
 
 int
 main (void)
 {
+  {
+    double value1;
+    char buf[64];
+
+    value1 = positive_NaNd();
+    sprintf (buf, "%g", value1);
+    ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
+
+    value1 = negative_NaNd();
+    sprintf (buf, "%g", value1);
+    ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
+  }
 #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
   /* Check the value of _PRINTF_NAN_LEN_MAX.  */
   {
@@ -56,7 +69,7 @@ main (void)
     memory_double value2;
     char buf[64];
 
-    value1 = NaNd();
+    value1 = SNaNd();
     sprintf (buf, "%g", value1);
     ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);