about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--stdio-common/printf_fp.c10
-rw-r--r--stdio-common/printf_fphex.c16
-rw-r--r--stdio-common/printf_size.c24
4 files changed, 32 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f6082e651..db3a61bb08 100644
--- 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.
diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c
index 0a611470bc..0853bc296a 100644
--- a/stdio-common/printf_fp.c
+++ b/stdio-common/printf_fp.c
@@ -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";
diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c
index 284cc6eec5..6cb71414f5 100644
--- a/stdio-common/printf_fphex.c
+++ b/stdio-common/printf_fphex.c
@@ -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);
 	}
     }
 
diff --git a/stdio-common/printf_size.c b/stdio-common/printf_size.c
index 957de2f571..651b3dba9d 100644
--- a/stdio-common/printf_size.c
+++ b/stdio-common/printf_size.c
@@ -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 ('+');