Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
authorBruno Haible <bruno@clisp.org>
Wed, 6 Jun 2007 02:20:57 +0000 (02:20 +0000)
committerBruno Haible <bruno@clisp.org>
Wed, 6 Jun 2007 02:20:57 +0000 (02:20 +0000)
19 files changed:
ChangeLog
modules/fprintf-posix
modules/printf-posix
modules/snprintf-posix
modules/sprintf-posix
modules/vasnprintf-posix
modules/vasprintf-posix
modules/vfprintf-posix
modules/vprintf-posix
modules/vsnprintf-posix
modules/vsprintf-posix
tests/test-snprintf-posix.c
tests/test-snprintf-posix.h
tests/test-sprintf-posix.c
tests/test-sprintf-posix.h
tests/test-vasnprintf-posix.c
tests/test-vasprintf-posix.c
tests/test-vsnprintf-posix.c
tests/test-vsprintf-posix.c

index 8637249e858835cf40f240058bf6161fcb706eda..5db2619be72236682d2ff6bf78d068fd4be9127a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,45 @@
+2007-06-05  Bruno Haible  <bruno@clisp.org>
+
+       Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64,
+       ia64.
+       * modules/printf-safe: New file.
+       * modules/fprintf-posix (Depends-on): Add printf-safe.
+       * modules/printf-posix (Depends-on): Likewise.
+       * modules/snprintf-posix (Depends-on): Likewise.
+       * modules/sprintf-posix (Depends-on): Likewise.
+       * modules/vasnprintf-posix (Depends-on): Likewise.
+       * modules/vasprintf-posix (Depends-on): Likewise.
+       * modules/vfprintf-posix (Depends-on): Likewise.
+       * modules/vprintf-posix (Depends-on): Likewise.
+       * modules/vsnprintf-posix (Depends-on): Likewise.
+       * modules/vsprintf-posix (Depends-on): Likewise.
+       * m4/printf.m4 (gl_PRINTF_INFINITE_LONG_DOUBLE): Require
+       AC_C_BIGENDIAN. Define CHECK_PRINTF_SAFE if printf-safe is used. Test
+       non-IEEE numbers on i386, x86_64, ia64. When cross-compiling, guess
+       "no" on i386, x86_64, ia64.
+       * tests/test-snprintf-posix.h (LDBL80_WORDS): New macro.
+       (test_function): Check result of %La, %Lf, %Le, %Lg on non-IEEE numbers
+       on i386, x86_64, ia64.
+       * tests/test-sprintf-posix.h (LDBL80_WORDS): New macro.
+       (test_function): Check result of %La, %Lf, %Le, %Lg on non-IEEE numbers
+       on i386, x86_64, ia64.
+       * tests/test-vasnprintf-posix.c: Include float.h.
+       (LDBL80_WORDS): New macro.
+       (test_function): Check result of %La, %Lf, %Le, %Lg on non-IEEE numbers
+       on i386, x86_64, ia64.
+       * tests/test-vasprintf-posix.c: Include float.h.
+       (LDBL80_WORDS): New macro.
+       (test_function): Check result of %La, %Lf, %Le, %Lg on non-IEEE numbers
+       on i386, x86_64, ia64.
+       * tests/test-snprintf-posix.c: Include float.h.
+       * tests/test-sprintf-posix.c: Likewise.
+       * tests/test-vsnprintf-posix.c: Likewise.
+       * tests/test-vsprintf-posix.c: Likewise.
+
 2007-06-05  Bruno Haible  <bruno@clisp.org>
 
        Fix isnanl so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
-       * m4/isnanl.m4 (gl_FUNC_ISNANL_WORKS): Require AC_C_BIGENDIAN. Tested
+       * m4/isnanl.m4 (gl_FUNC_ISNANL_WORKS): Require AC_C_BIGENDIAN. Test
        non-IEEE numbers on i386, x86_64, ia64.
        (gl_LONG_DOUBLE_EXPONENT_LOCATION): Require AC_C_BIGENDIAN.
        * lib/isnan.c (FUNC): Add special code for i386, x86_64, ia64.
index 42109be5d61ac9e713cbb7b9f2732a0f0c61168c..40e606c12c6eef76c9272c1f0acffaa7aab9a8b1 100644 (file)
@@ -17,6 +17,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_FPRINTF_POSIX
index ba56fa032a68f5a963f53a7a60cc05d823ab476a..b690c729e008ae998232ebdd04c4914254115150 100644 (file)
@@ -9,6 +9,7 @@ m4/printf.m4
 Depends-on:
 stdio
 vfprintf-posix
+printf-safe
 
 configure.ac:
 gl_FUNC_PRINTF_POSIX
index c4808357583f38a9c2144113b2e5204dc293dae8..0a5e8d6936a4dd2db4dee3f28a0521764636c5ee 100644 (file)
@@ -16,6 +16,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_SNPRINTF_POSIX
index fceae7b8a1943b8cd8af815af37cb9e25fe3bec7..7bfa94b23e711a1856d791112777e637b04e442a 100644 (file)
@@ -16,6 +16,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_SPRINTF_POSIX
index 9d693af4dc04b9a3eb0dfe04a92aa57e4da5563b..b7017182427ba77548997c016c97e77036e10c9a 100644 (file)
@@ -15,6 +15,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_VASNPRINTF_POSIX
index 48f902f263c9fe0daa6f82d92ba328752e1dbe63..2b75dff791505192f4eea186aadcceaa61382521 100644 (file)
@@ -15,6 +15,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_VASPRINTF_POSIX
index 539d5257668dfd5c61debfaadcbffb99a97bc48e..7d0b8cd39fe209d06a9bd694d5297dff974389c0 100644 (file)
@@ -17,6 +17,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_VFPRINTF_POSIX
index 4e8601a57f3fcff6eb795ba38ccca014004a6efe..2007000ae2b8827a0b9f11adacbfe13db3a638f6 100644 (file)
@@ -9,6 +9,7 @@ m4/printf.m4
 Depends-on:
 stdio
 vfprintf-posix
+printf-safe
 
 configure.ac:
 gl_FUNC_VPRINTF_POSIX
index f1a5674eca7131c768fc6760a3fa7f1322926fe4..fc499995abd810407d0216013b748eea73cca366 100644 (file)
@@ -16,6 +16,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_VSNPRINTF_POSIX
index 4fc68868c273a93ab6881f63f30639a0b5e19deb..ba79781a26ab9bcc840d8c0433c64bcc3648f23b 100644 (file)
@@ -16,6 +16,7 @@ printf-frexp
 printf-frexpl
 signbit
 fpucw
+printf-safe
 
 configure.ac:
 gl_FUNC_VSPRINTF_POSIX
index 901525646dd84d3ef89cfb82f74294d25d71860a..593f20f526e2023a2d75ba2c23d4a0a9d8862736 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 
+#include <float.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdint.h>
index 346d32e08461a58855c22145738d68a69f5feda2..46412ba31385a4701af7f50e8b444f0c728cd869 100644 (file)
@@ -38,6 +38,19 @@ have_minus_zero ()
   return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
 }
 
+/* Representation of an 80-bit 'long double' as an initializer for a sequence
+   of 'unsigned int' words.  */
+#ifdef WORDS_BIGENDIAN
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
+      ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),    \
+      (unsigned int) (mantlo) << 16                                        \
+    }
+#else
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { mantlo, manthi, exponent }
+#endif
+
 static int
 strmatch (const char *pattern, const char *string)
 {
@@ -465,6 +478,93 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Rounding near the decimal point.  */
     char result[100];
@@ -1073,6 +1173,93 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Width.  */
     char result[100];
@@ -1787,6 +1974,93 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Width.  */
     char result[100];
@@ -2301,6 +2575,93 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[100];
+    int retval =
+      my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Width.  */
     char result[100];
index 07a556f8276f2568a3584e700aabf2b863951cf2..6416d85a379a105b2544a086b2c6ed85e1d1a0d3 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 
+#include <float.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdint.h>
index f178803f61bdaf5da71a110200dba5e454295cb5..df0adccf73822578a73472bd84d5b2dbab028edc 100644 (file)
@@ -38,6 +38,19 @@ have_minus_zero ()
   return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
 }
 
+/* Representation of an 80-bit 'long double' as an initializer for a sequence
+   of 'unsigned int' words.  */
+#ifdef WORDS_BIGENDIAN
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
+      ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),    \
+      (unsigned int) (mantlo) << 16                                        \
+    }
+#else
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { mantlo, manthi, exponent }
+#endif
+
 static int
 strmatch (const char *pattern, const char *string)
 {
@@ -69,7 +82,7 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas
     }
   return 0;
 }
-         
+
 static void
 test_function (int (*my_sprintf) (char *, const char *, ...))
 {
@@ -451,6 +464,93 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Rounding near the decimal point.  */
     char result[1000];
@@ -1053,6 +1153,93 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Width.  */
     char result[1000];
@@ -1761,6 +1948,93 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Width.  */
     char result[1000];
@@ -2275,6 +2549,93 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
            && strcmp (result + strlen (result) - 3, " 33") == 0);
     ASSERT (retval == strlen (result));
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char result[1000];
+    int retval =
+      my_sprintf (result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+#endif
 
   { /* Width.  */
     char result[1000];
index 3d20a83af1a3905f604ee5e892573303c3066469..53b679918700db079cee72e78486c74e27006ce7 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "vasnprintf.h"
 
+#include <float.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -61,6 +62,19 @@ have_minus_zero ()
   return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
 }
 
+/* Representation of an 80-bit 'long double' as an initializer for a sequence
+   of 'unsigned int' words.  */
+#ifdef WORDS_BIGENDIAN
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
+      ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),    \
+      (unsigned int) (mantlo) << 16                                        \
+    }
+#else
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { mantlo, manthi, exponent }
+#endif
+
 static int
 strmatch (const char *pattern, const char *string)
 {
@@ -566,6 +580,107 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     ASSERT (length == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Rounding near the decimal point.  */
     size_t length;
@@ -1260,6 +1375,107 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     ASSERT (length == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Width.  */
     size_t length;
@@ -2089,6 +2305,107 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     ASSERT (length == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Width.  */
     size_t length;
@@ -2683,6 +3000,107 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     ASSERT (length == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Width.  */
     size_t length;
index 7ff05daca46c8d1c6e6046367deb5850decb639f..3d7aa43956130cfb631bc304b67541bb9f71ea66 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 
+#include <float.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -61,6 +62,19 @@ have_minus_zero ()
   return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
 }
 
+/* Representation of an 80-bit 'long double' as an initializer for a sequence
+   of 'unsigned int' words.  */
+#ifdef WORDS_BIGENDIAN
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
+      ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),    \
+      (unsigned int) (mantlo) << 16                                        \
+    }
+#else
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { mantlo, manthi, exponent }
+#endif
+
 static int
 strmatch (const char *pattern, const char *string)
 {
@@ -547,6 +561,107 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     ASSERT (retval == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Rounding near the decimal point.  */
     char *result;
@@ -1241,6 +1356,107 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     ASSERT (retval == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Width.  */
     char *result;
@@ -2070,6 +2286,107 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     ASSERT (retval == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Width.  */
     char *result;
@@ -2664,6 +2981,107 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     ASSERT (retval == strlen (result));
     free (result);
   }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
+     Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
+       Intel IA-64 Architecture Software Developer's Manual, Volume 1:
+       Application Architecture.
+       Table 5-2 "Floating-Point Register Encodings"
+       Figure 5-6 "Memory to Floating-Point Register Data Translation"
+   */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    char *result;
+    int retval =
+      my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strlen (result) >= 3 + 3
+           && strisnan (result, 0, strlen (result) - 3, 0)
+           && strcmp (result + strlen (result) - 3, " 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+#endif
 
   { /* Width.  */
     char *result;
index 0c3d807f8169866d99a894b70afcf02da77d467f..aa2c9a9936595af7e1f37dd941dc5b5db4e13058 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 
+#include <float.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
index d0297bbff8282b1f0f5d3aad71a01eedce785039..6aa1d5c729ee73a526b4f840c377637eb81f6f09 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 
+#include <float.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>