isinf returns the sign of the number, use it in printf*
authorUlrich Drepper <drepper@gmail.com>
Sat, 8 Oct 2011 12:22:44 +0000 (08:22 -0400)
committerUlrich Drepper <drepper@gmail.com>
Sat, 8 Oct 2011 12:22:44 +0000 (08:22 -0400)
ChangeLog
stdio-common/printf_fp.c
stdio-common/printf_fphex.c
stdio-common/printf_size.c

index 6f6082e..db3a61b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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_exp10f.c: Likewise.
        * math/e_exp10l.c: Likewise.
index 0a61147..0853bc2 100644 (file)
@@ -334,6 +334,7 @@ ___printf_fp (FILE *fp,
       fpnum.ldbl = *(const long double *) args[0];
 
       /* Check for special values: not a number or infinity.  */
+      int res;
       if (__isnanl (fpnum.ldbl))
        {
          union ieee854_long_double u = { .d = fpnum.ldbl };
@@ -349,9 +350,9 @@ ___printf_fp (FILE *fp,
                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))
            {
              special = "INF";
@@ -379,6 +380,7 @@ ___printf_fp (FILE *fp,
       fpnum.dbl = *(const double *) args[0];
 
       /* Check for special values: not a number or infinity.  */
+      int res;
       if (__isnan (fpnum.dbl))
        {
          union ieee754_double u = { .d = fpnum.dbl };
@@ -394,9 +396,9 @@ ___printf_fp (FILE *fp,
              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))
            {
              special = "INF";
index 284cc6e..6cb7141 100644 (file)
@@ -180,7 +180,8 @@ __printf_fphex (FILE *fp,
        }
       else
        {
-         if (__isinfl (fpnum.ldbl.d))
+         int res = __isinfl (fpnum.ldbl.d);
+         if (res)
            {
              if (isupper (info->spec))
                {
@@ -192,9 +193,10 @@ __printf_fphex (FILE *fp,
                  special = "inf";
                  wspecial = L"inf";
                }
+             negative = res < 0;
            }
-
-         negative = signbit (fpnum.ldbl.d);
+         else
+           negative = signbit (fpnum.ldbl.d);
        }
     }
   else
@@ -219,7 +221,8 @@ __printf_fphex (FILE *fp,
        }
       else
        {
-         if (__isinf (fpnum.dbl.d))
+         int res = __isinf (fpnum.dbl.d);
+         if (res)
            {
              if (isupper (info->spec))
                {
@@ -231,9 +234,10 @@ __printf_fphex (FILE *fp,
                  special = "inf";
                  wspecial = L"inf";
                }
+             negative = res < 0;
            }
-
-         negative = signbit (fpnum.dbl.d);
+         else
+           negative = signbit (fpnum.dbl.d);
        }
     }
 
index 957de2f..651b3db 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
    Based on a proposal by Larry McVoy <lm@sgi.com>.
@@ -109,7 +109,7 @@ __printf_size (FILE *fp, const struct printf_info *info,
   fpnum;
   const void *ptr = &fpnum;
 
-  int negative = 0;
+  int fpnum_sign = 0;
 
   /* "NaN" or "Inf" for the special cases.  */
   const char *special = NULL;
@@ -118,7 +118,7 @@ __printf_size (FILE *fp, const struct printf_info *info,
   struct printf_info fp_info;
   int done = 0;
   int wide = info->wide;
-
+  int res;
 
   /* Fetch the argument value. */
 #ifndef __NO_LONG_DOUBLE_MATH
@@ -131,14 +131,13 @@ __printf_size (FILE *fp, const struct printf_info *info,
        {
          special = "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";
          wspecial = L"inf";
-
-         negative = fpnum.ldbl.d < 0;
        }
       else
        while (fpnum.ldbl.d >= divisor && tag[1] != '\0')
@@ -157,14 +156,13 @@ __printf_size (FILE *fp, const struct printf_info *info,
        {
          special = "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";
          wspecial = L"inf";
-
-         negative = fpnum.dbl.d < 0;
        }
       else
        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;
 
-      if (negative || info->showsign || info->space)
+      if (fpnum_sign < 0 || info->showsign || info->space)
        --width;
       width -= 3;
 
       if (!info->left && width > 0)
        PADN (' ', width);
 
-      if (negative)
+      if (fpnum_sign < 0)
        outchar ('-');
       else if (info->showsign)
        outchar ('+');