From ee6d9baacd6be1baf7c81422f2f716e3fe280c05 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 6 Jun 2007 02:20:57 +0000 Subject: [PATCH] Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64. --- ChangeLog | 40 +++- modules/fprintf-posix | 1 + modules/printf-posix | 1 + modules/snprintf-posix | 1 + modules/sprintf-posix | 1 + modules/vasnprintf-posix | 1 + modules/vasprintf-posix | 1 + modules/vfprintf-posix | 1 + modules/vprintf-posix | 1 + modules/vsnprintf-posix | 1 + modules/vsprintf-posix | 1 + tests/test-snprintf-posix.c | 1 + tests/test-snprintf-posix.h | 361 ++++++++++++++++++++++++++++++++++++ tests/test-sprintf-posix.c | 1 + tests/test-sprintf-posix.h | 363 +++++++++++++++++++++++++++++++++++- tests/test-vasnprintf-posix.c | 418 ++++++++++++++++++++++++++++++++++++++++++ tests/test-vasprintf-posix.c | 418 ++++++++++++++++++++++++++++++++++++++++++ tests/test-vsnprintf-posix.c | 1 + tests/test-vsprintf-posix.c | 1 + 19 files changed, 1612 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8637249e8..5db2619be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,45 @@ 2007-06-05 Bruno Haible + 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 + 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 42109be5d..40e606c12 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 ba56fa032..b690c729e 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 c48083575..0a5e8d693 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 fceae7b8a..7bfa94b23 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 9d693af4d..b70171824 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 48f902f26..2b75dff79 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 539d52576..7d0b8cd39 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 4e8601a57..2007000ae 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 f1a5674ec..fc499995a 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 4fc68868c..ba79781a2 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 901525646..593f20f52 100644 --- a/tests/test-snprintf-posix.c +++ b/tests/test-snprintf-posix.c @@ -21,6 +21,7 @@ #include +#include #include #include #include diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 346d32e08..46412ba31 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 07a556f82..6416d85a3 100644 --- a/tests/test-sprintf-posix.c +++ b/tests/test-sprintf-posix.c @@ -21,6 +21,7 @@ #include +#include #include #include #include diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index f178803f6..df0adccf7 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 3d20a83af..53b679918 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -21,6 +21,7 @@ #include "vasnprintf.h" +#include #include #include #include @@ -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 7ff05daca..3d7aa4395 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -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 0c3d807f8..aa2c9a993 100644 --- a/tests/test-vsnprintf-posix.c +++ b/tests/test-vsnprintf-posix.c @@ -21,6 +21,7 @@ #include +#include #include #include #include diff --git a/tests/test-vsprintf-posix.c b/tests/test-vsprintf-posix.c index d0297bbff..6aa1d5c72 100644 --- a/tests/test-vsprintf-posix.c +++ b/tests/test-vsprintf-posix.c @@ -21,6 +21,7 @@ #include +#include #include #include #include -- 2.11.0