isinf returns the sign of the number, use it in printf*

This commit is contained in:
Ulrich Drepper 2011-10-08 08:22:44 -04:00
parent 9277c06437
commit 187da0aedc
4 changed files with 32 additions and 23 deletions

View File

@ -1,5 +1,10 @@
2011-10-08 Ulrich Drepper <drepper@gmail.com> 2011-10-08 Ulrich Drepper <drepper@gmail.com>
* stdio-common/printf_fp.c: Use the fact that isinf returns the sign
of the number.
* stdio-common/printf_fphex.c: Likewise.
* stdio-common/printf_size.c: Likewise.
* math/e_exp10.c: Include math_private.h using <...> not "...". * math/e_exp10.c: Include math_private.h using <...> not "...".
* math/e_exp10f.c: Likewise. * math/e_exp10f.c: Likewise.
* math/e_exp10l.c: Likewise. * math/e_exp10l.c: Likewise.

View File

@ -334,6 +334,7 @@ ___printf_fp (FILE *fp,
fpnum.ldbl = *(const long double *) args[0]; fpnum.ldbl = *(const long double *) args[0];
/* Check for special values: not a number or infinity. */ /* Check for special values: not a number or infinity. */
int res;
if (__isnanl (fpnum.ldbl)) if (__isnanl (fpnum.ldbl))
{ {
union ieee854_long_double u = { .d = fpnum.ldbl }; union ieee854_long_double u = { .d = fpnum.ldbl };
@ -349,9 +350,9 @@ ___printf_fp (FILE *fp,
wspecial = L"nan"; wspecial = L"nan";
} }
} }
else if (__isinfl (fpnum.ldbl)) else if ((res = __isinfl (fpnum.ldbl)))
{ {
is_neg = fpnum.ldbl < 0; is_neg = res < 0;
if (isupper (info->spec)) if (isupper (info->spec))
{ {
special = "INF"; special = "INF";
@ -379,6 +380,7 @@ ___printf_fp (FILE *fp,
fpnum.dbl = *(const double *) args[0]; fpnum.dbl = *(const double *) args[0];
/* Check for special values: not a number or infinity. */ /* Check for special values: not a number or infinity. */
int res;
if (__isnan (fpnum.dbl)) if (__isnan (fpnum.dbl))
{ {
union ieee754_double u = { .d = fpnum.dbl }; union ieee754_double u = { .d = fpnum.dbl };
@ -394,9 +396,9 @@ ___printf_fp (FILE *fp,
wspecial = L"nan"; wspecial = L"nan";
} }
} }
else if (__isinf (fpnum.dbl)) else if ((res = __isinf (fpnum.dbl)))
{ {
is_neg = fpnum.dbl < 0; is_neg = res < 0;
if (isupper (info->spec)) if (isupper (info->spec))
{ {
special = "INF"; special = "INF";

View File

@ -180,7 +180,8 @@ __printf_fphex (FILE *fp,
} }
else else
{ {
if (__isinfl (fpnum.ldbl.d)) int res = __isinfl (fpnum.ldbl.d);
if (res)
{ {
if (isupper (info->spec)) if (isupper (info->spec))
{ {
@ -192,9 +193,10 @@ __printf_fphex (FILE *fp,
special = "inf"; special = "inf";
wspecial = L"inf"; wspecial = L"inf";
} }
negative = res < 0;
} }
else
negative = signbit (fpnum.ldbl.d); negative = signbit (fpnum.ldbl.d);
} }
} }
else else
@ -219,7 +221,8 @@ __printf_fphex (FILE *fp,
} }
else else
{ {
if (__isinf (fpnum.dbl.d)) int res = __isinf (fpnum.dbl.d);
if (res)
{ {
if (isupper (info->spec)) if (isupper (info->spec))
{ {
@ -231,9 +234,10 @@ __printf_fphex (FILE *fp,
special = "inf"; special = "inf";
wspecial = L"inf"; wspecial = L"inf";
} }
negative = res < 0;
} }
else
negative = signbit (fpnum.dbl.d); negative = signbit (fpnum.dbl.d);
} }
} }

View File

@ -1,5 +1,5 @@
/* Print size value using units for orders of magnitude. /* Print size value using units for orders of magnitude.
Copyright (C) 1997-2002, 2004, 2006 Free Software Foundation, Inc. Copyright (C) 1997-2002, 2004, 2006, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Based on a proposal by Larry McVoy <lm@sgi.com>. Based on a proposal by Larry McVoy <lm@sgi.com>.
@ -109,7 +109,7 @@ __printf_size (FILE *fp, const struct printf_info *info,
fpnum; fpnum;
const void *ptr = &fpnum; const void *ptr = &fpnum;
int negative = 0; int fpnum_sign = 0;
/* "NaN" or "Inf" for the special cases. */ /* "NaN" or "Inf" for the special cases. */
const char *special = NULL; const char *special = NULL;
@ -118,7 +118,7 @@ __printf_size (FILE *fp, const struct printf_info *info,
struct printf_info fp_info; struct printf_info fp_info;
int done = 0; int done = 0;
int wide = info->wide; int wide = info->wide;
int res;
/* Fetch the argument value. */ /* Fetch the argument value. */
#ifndef __NO_LONG_DOUBLE_MATH #ifndef __NO_LONG_DOUBLE_MATH
@ -131,14 +131,13 @@ __printf_size (FILE *fp, const struct printf_info *info,
{ {
special = "nan"; special = "nan";
wspecial = L"nan"; wspecial = L"nan";
negative = 0; // fpnum_sign = 0; Already zero
} }
else if (__isinfl (fpnum.ldbl.d)) else if ((res = __isinfl (fpnum.ldbl.d)))
{ {
fpnum_sign = res;
special = "inf"; special = "inf";
wspecial = L"inf"; wspecial = L"inf";
negative = fpnum.ldbl.d < 0;
} }
else else
while (fpnum.ldbl.d >= divisor && tag[1] != '\0') while (fpnum.ldbl.d >= divisor && tag[1] != '\0')
@ -157,14 +156,13 @@ __printf_size (FILE *fp, const struct printf_info *info,
{ {
special = "nan"; special = "nan";
wspecial = L"nan"; wspecial = L"nan";
negative = 0; // fpnum_sign = 0; Already zero
} }
else if (__isinf (fpnum.dbl.d)) else if ((res = __isinf (fpnum.dbl.d)))
{ {
fpnum_sign = res;
special = "inf"; special = "inf";
wspecial = L"inf"; wspecial = L"inf";
negative = fpnum.dbl.d < 0;
} }
else else
while (fpnum.dbl.d >= divisor && tag[1] != '\0') while (fpnum.dbl.d >= divisor && tag[1] != '\0')
@ -178,14 +176,14 @@ __printf_size (FILE *fp, const struct printf_info *info,
{ {
int width = info->prec > info->width ? info->prec : info->width; int width = info->prec > info->width ? info->prec : info->width;
if (negative || info->showsign || info->space) if (fpnum_sign < 0 || info->showsign || info->space)
--width; --width;
width -= 3; width -= 3;
if (!info->left && width > 0) if (!info->left && width > 0)
PADN (' ', width); PADN (' ', width);
if (negative) if (fpnum_sign < 0)
outchar ('-'); outchar ('-');
else if (info->showsign) else if (info->showsign)
outchar ('+'); outchar ('+');