mirror of
git://sourceware.org/git/glibc.git
synced 2024-11-21 01:12:26 +08:00
Print sign of NaN values.
This commit is contained in:
parent
659a63fb7b
commit
003c9895a8
@ -1,5 +1,10 @@
|
||||
2009-08-23 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* stdio-common/printf_fp.c: ISO C expects to print the sign of NaN
|
||||
as well.
|
||||
* stdio-common/printf_fphex.c: Likewise.
|
||||
* stdio-common/tstdiomisc.c: Add more tests.
|
||||
|
||||
* locale/locale.h: Include xlocale.h and the thread-local locale
|
||||
declarations for XPG7, not XPG6.
|
||||
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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, "%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, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
|
||||
result |= strcmp (buf, "inf INF") != 0;
|
||||
printf ("expected \"inf INF\", 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);
|
||||
|
||||
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);
|
||||
infval = DBL_MAX * DBL_MAX;
|
||||
|
||||
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",
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user