summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog40
-rw-r--r--modules/fprintf-posix1
-rw-r--r--modules/printf-posix1
-rw-r--r--modules/snprintf-posix1
-rw-r--r--modules/sprintf-posix1
-rw-r--r--modules/vasnprintf-posix1
-rw-r--r--modules/vasprintf-posix1
-rw-r--r--modules/vfprintf-posix1
-rw-r--r--modules/vprintf-posix1
-rw-r--r--modules/vsnprintf-posix1
-rw-r--r--modules/vsprintf-posix1
-rw-r--r--tests/test-snprintf-posix.c1
-rw-r--r--tests/test-snprintf-posix.h361
-rw-r--r--tests/test-sprintf-posix.c1
-rw-r--r--tests/test-sprintf-posix.h363
-rw-r--r--tests/test-vasnprintf-posix.c418
-rw-r--r--tests/test-vasprintf-posix.c418
-rw-r--r--tests/test-vsnprintf-posix.c1
-rw-r--r--tests/test-vsprintf-posix.c1
19 files changed, 1612 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 8637249e85..5db2619be7 100644
--- 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.
diff --git a/modules/fprintf-posix b/modules/fprintf-posix
index 42109be5d6..40e606c12c 100644
--- a/modules/fprintf-posix
+++ b/modules/fprintf-posix
@@ -17,6 +17,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_FPRINTF_POSIX
diff --git a/modules/printf-posix b/modules/printf-posix
index ba56fa032a..b690c729e0 100644
--- a/modules/printf-posix
+++ b/modules/printf-posix
@@ -9,6 +9,7 @@ m4/printf.m4
Depends-on:
stdio
vfprintf-posix
+printf-safe
configure.ac:
gl_FUNC_PRINTF_POSIX
diff --git a/modules/snprintf-posix b/modules/snprintf-posix
index c480835758..0a5e8d6936 100644
--- a/modules/snprintf-posix
+++ b/modules/snprintf-posix
@@ -16,6 +16,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_SNPRINTF_POSIX
diff --git a/modules/sprintf-posix b/modules/sprintf-posix
index fceae7b8a1..7bfa94b23e 100644
--- a/modules/sprintf-posix
+++ b/modules/sprintf-posix
@@ -16,6 +16,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_SPRINTF_POSIX
diff --git a/modules/vasnprintf-posix b/modules/vasnprintf-posix
index 9d693af4dc..b701718242 100644
--- a/modules/vasnprintf-posix
+++ b/modules/vasnprintf-posix
@@ -15,6 +15,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_VASNPRINTF_POSIX
diff --git a/modules/vasprintf-posix b/modules/vasprintf-posix
index 48f902f263..2b75dff791 100644
--- a/modules/vasprintf-posix
+++ b/modules/vasprintf-posix
@@ -15,6 +15,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_VASPRINTF_POSIX
diff --git a/modules/vfprintf-posix b/modules/vfprintf-posix
index 539d525766..7d0b8cd39f 100644
--- a/modules/vfprintf-posix
+++ b/modules/vfprintf-posix
@@ -17,6 +17,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_VFPRINTF_POSIX
diff --git a/modules/vprintf-posix b/modules/vprintf-posix
index 4e8601a57f..2007000ae2 100644
--- a/modules/vprintf-posix
+++ b/modules/vprintf-posix
@@ -9,6 +9,7 @@ m4/printf.m4
Depends-on:
stdio
vfprintf-posix
+printf-safe
configure.ac:
gl_FUNC_VPRINTF_POSIX
diff --git a/modules/vsnprintf-posix b/modules/vsnprintf-posix
index f1a5674eca..fc499995ab 100644
--- a/modules/vsnprintf-posix
+++ b/modules/vsnprintf-posix
@@ -16,6 +16,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_VSNPRINTF_POSIX
diff --git a/modules/vsprintf-posix b/modules/vsprintf-posix
index 4fc68868c2..ba79781a26 100644
--- a/modules/vsprintf-posix
+++ b/modules/vsprintf-posix
@@ -16,6 +16,7 @@ printf-frexp
printf-frexpl
signbit
fpucw
+printf-safe
configure.ac:
gl_FUNC_VSPRINTF_POSIX
diff --git a/tests/test-snprintf-posix.c b/tests/test-snprintf-posix.c
index 901525646d..593f20f526 100644
--- a/tests/test-snprintf-posix.c
+++ b/tests/test-snprintf-posix.c
@@ -21,6 +21,7 @@
#include <stdio.h>
+#include <float.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h
index 346d32e084..46412ba313 100644
--- a/tests/test-snprintf-posix.h
+++ b/tests/test-snprintf-posix.h
@@ -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];
diff --git a/tests/test-sprintf-posix.c b/tests/test-sprintf-posix.c
index 07a556f827..6416d85a37 100644
--- a/tests/test-sprintf-posix.c
+++ b/tests/test-sprintf-posix.c
@@ -21,6 +21,7 @@
#include <stdio.h>
+#include <float.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h
index f178803f61..df0adccf73 100644
--- a/tests/test-sprintf-posix.h
+++ b/tests/test-sprintf-posix.h
@@ -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];
diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c
index 3d20a83af1..53b6799187 100644
--- a/tests/test-vasnprintf-posix.c
+++ b/tests/test-vasnprintf-posix.c
@@ -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;
diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c
index 7ff05daca4..3d7aa43956 100644
--- a/tests/test-vasprintf-posix.c
+++ b/tests/test-vasprintf-posix.c
@@ -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;
diff --git a/tests/test-vsnprintf-posix.c b/tests/test-vsnprintf-posix.c
index 0c3d807f81..aa2c9a9936 100644
--- a/tests/test-vsnprintf-posix.c
+++ b/tests/test-vsnprintf-posix.c
@@ -21,6 +21,7 @@
#include <stdio.h>
+#include <float.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
diff --git a/tests/test-vsprintf-posix.c b/tests/test-vsprintf-posix.c
index d0297bbff8..6aa1d5c729 100644
--- a/tests/test-vsprintf-posix.c
+++ b/tests/test-vsprintf-posix.c
@@ -21,6 +21,7 @@
#include <stdio.h>
+#include <float.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>