diff options
author | Ulrich Drepper <drepper@redhat.com> | 2009-08-23 11:57:52 -0700 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2009-08-23 11:57:52 -0700 |
commit | 003c9895a89e71767ad64bafac1ca99622be2eb7 (patch) | |
tree | 86902c3ea811ee8c4b8507a026f5563306340357 /stdio-common | |
parent | 659a63fb7ba0b2c9bc45034283a302afe56a6ebe (diff) | |
download | glibc-003c9895a89e71767ad64bafac1ca99622be2eb7.zip glibc-003c9895a89e71767ad64bafac1ca99622be2eb7.tar.gz glibc-003c9895a89e71767ad64bafac1ca99622be2eb7.tar.bz2 |
Print sign of NaN values.
Diffstat (limited to 'stdio-common')
-rw-r--r-- | stdio-common/printf_fp.c | 9 | ||||
-rw-r--r-- | stdio-common/printf_fphex.c | 4 | ||||
-rw-r--r-- | stdio-common/tstdiomisc.c | 132 |
3 files changed, 122 insertions, 23 deletions
diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index 43c43c2..cd3ada6 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -28,6 +28,7 @@ #include <float.h> #include <gmp-mparam.h> #include <gmp.h> +#include <ieee754.h> #include <stdlib/gmp-impl.h> #include <stdlib/longlong.h> #include <stdlib/fpioconst.h> @@ -335,6 +336,8 @@ ___printf_fp (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnanl (fpnum.ldbl)) { + union ieee854_long_double u = { .d = fpnum.ldbl }; + is_neg = u.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -345,10 +348,10 @@ ___printf_fp (FILE *fp, special = "nan"; wspecial = L"nan"; } - is_neg = 0; } else if (__isinfl (fpnum.ldbl)) { + is_neg = fpnum.ldbl < 0; if (isupper (info->spec)) { special = "INF"; @@ -359,7 +362,6 @@ ___printf_fp (FILE *fp, special = "inf"; wspecial = L"inf"; } - is_neg = fpnum.ldbl < 0; } else { @@ -379,7 +381,8 @@ ___printf_fp (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnan (fpnum.dbl)) { - is_neg = 0; + union ieee754_double u = { .d = fpnum.dbl }; + is_neg = u.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c index 4e30d94..551c873 100644 --- a/stdio-common/printf_fphex.c +++ b/stdio-common/printf_fphex.c @@ -172,6 +172,7 @@ __printf_fphex (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnanl (fpnum.ldbl.d)) { + negative = fpnum.ldbl.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -182,7 +183,6 @@ __printf_fphex (FILE *fp, special = "nan"; wspecial = L"nan"; } - negative = 0; } else { @@ -211,6 +211,7 @@ __printf_fphex (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnan (fpnum.dbl.d)) { + negative = fpnum.dbl.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -221,7 +222,6 @@ __printf_fphex (FILE *fp, special = "nan"; wspecial = L"nan"; } - negative = 0; } else { diff --git a/stdio-common/tstdiomisc.c b/stdio-common/tstdiomisc.c index db038fa..c1c6895 100644 --- a/stdio-common/tstdiomisc.c +++ b/stdio-common/tstdiomisc.c @@ -47,33 +47,129 @@ t2 (void) } volatile double nanval; +volatile double infval; +volatile long double lnanval; +volatile long double linfval; static int F (void) { - char buf[20]; - wchar_t wbuf[10]; + char buf[80]; + wchar_t wbuf[40]; int result; nanval = NAN; - snprintf (buf, sizeof buf, "%f %F", nanval, nanval); - result = strcmp (buf, "nan NAN") != 0; - printf ("expected \"nan NAN\", got \"%s\"\n", buf); - - snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX); - result |= strcmp (buf, "inf INF") != 0; - printf ("expected \"inf INF\", got \"%s\"\n", buf); - - swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", nanval, nanval); - result |= wcscmp (wbuf, L"nan NAN") != 0; - printf ("expected L\"nan NAN\", got L\"%S\"\n", wbuf); - - swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", - DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX); - result |= wcscmp (wbuf, L"inf INF") != 0; - printf ("expected L\"inf INF\", got L\"%S\"\n", wbuf); + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + nanval, nanval, nanval, nanval, nanval, nanval, nanval, nanval); + result = strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + -nanval, -nanval, -nanval, -nanval, + -nanval, -nanval, -nanval, -nanval); + result = strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n", + buf); + + infval = DBL_MAX * DBL_MAX; + + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + infval, infval, infval, infval, infval, infval, infval, infval); + result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0; + printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + -infval, -infval, -infval, -infval, + -infval, -infval, -infval, -infval); + result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n", + buf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + nanval, nanval, nanval, nanval, nanval, nanval, nanval, nanval); + result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + -nanval, -nanval, -nanval, -nanval, + -nanval, -nanval, -nanval, -nanval); + result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n", + wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + infval, infval, infval, infval, infval, infval, infval, infval); + result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0; + printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + -infval, -infval, -infval, -infval, + -infval, -infval, -infval, -infval); + result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n", + wbuf); + + lnanval = NAN; + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + lnanval, lnanval, lnanval, lnanval, + lnanval, lnanval, lnanval, lnanval); + result = strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + -lnanval, -lnanval, -lnanval, -lnanval, + -lnanval, -lnanval, -lnanval, -lnanval); + result = strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n", + buf); + + linfval = LDBL_MAX * LDBL_MAX; + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + linfval, linfval, linfval, linfval, + linfval, linfval, linfval, linfval); + result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0; + printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + -linfval, -linfval, -linfval, -linfval, + -linfval, -linfval, -linfval, -linfval); + result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n", + buf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + lnanval, lnanval, lnanval, lnanval, + lnanval, lnanval, lnanval, lnanval); + result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + -lnanval, -lnanval, -lnanval, -lnanval, + -lnanval, -lnanval, -lnanval, -lnanval); + result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n", + wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + linfval, linfval, linfval, linfval, + linfval, linfval, linfval, linfval); + result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0; + printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + -linfval, -linfval, -linfval, -linfval, + -linfval, -linfval, -linfval, -linfval); + result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n", + wbuf); return result; } |