summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-06-06 02:20:57 +0000
committerBruno Haible <bruno@clisp.org>2007-06-06 02:20:57 +0000
commitee6d9baacd6be1baf7c81422f2f716e3fe280c05 (patch)
tree99b2cea4b29597add28baf39119d963eb531c346 /tests
parentb2d043308f9a2cd45991712996e2b50abc83581d (diff)
downloadgnulib-ee6d9baacd6be1baf7c81422f2f716e3fe280c05.tar.gz
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Diffstat (limited to 'tests')
-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
8 files changed, 1563 insertions, 1 deletions
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>