[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commits] r20672 - in /fsf/trunk/libc: ./ nptl/ nptl/sysdeps/pthread/ stdio-common/



Author: eglibc
Date: Sat Sep 15 00:01:40 2012
New Revision: 20672

Log:
Import glibc-mainline for 2012-09-15

Added:
    fsf/trunk/libc/stdio-common/tst-printf-round.c
Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/NEWS
    fsf/trunk/libc/nptl/ChangeLog
    fsf/trunk/libc/nptl/sysdeps/pthread/pthread.h
    fsf/trunk/libc/stdio-common/Makefile
    fsf/trunk/libc/stdio-common/printf_fp.c

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Sat Sep 15 00:01:40 2012
@@ -1,3 +1,15 @@
+2012-09-14  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
+
+	[BZ #5044]
+	* stdio-common/printf_fp.c: Include <stdbool.h> and
+	<rounding-mode.h>.
+	(___printf_fp): Determine rounding using get_rounding_mode and
+	round_away.
+	* stdio-common/tst-printf-round.c: New file.
+	* stdio-common/Makefile (tests): Add tst-printf-round.
+	(link-libm): New variable.
+	($(objpfx)tst-printf-round): Depend in $(link-libm).
+
 2012-09-13  H.J. Lu  <hongjiu.lu@xxxxxxxxx>
 
 	[BZ #14576]

Modified: fsf/trunk/libc/NEWS
==============================================================================
--- fsf/trunk/libc/NEWS (original)
+++ fsf/trunk/libc/NEWS Sat Sep 15 00:01:40 2012
@@ -13,7 +13,7 @@
   13542, 13717, 13696, 13939, 13966, 14042, 14090, 14166, 14150, 14151,
   14154, 14157, 14166, 14173, 14195, 14237, 14252, 14283, 14298, 14303,
   14307, 14328, 14331, 14336, 14337, 14347, 14349, 14459, 14476, 14505,
-  14510, 14516, 14518, 14519, 14532, 14538, 14544, 14545, 14576,
+  14510, 14516, 14518, 14519, 14532, 14538, 14544, 14545, 14576, 14583
 
 * Support for STT_GNU_IFUNC symbols added for s390 and s390x.
   Optimized versions of memcpy, memset, and memcmp added for System z10 and

Modified: fsf/trunk/libc/nptl/ChangeLog
==============================================================================
--- fsf/trunk/libc/nptl/ChangeLog (original)
+++ fsf/trunk/libc/nptl/ChangeLog Sat Sep 15 00:01:40 2012
@@ -1,3 +1,8 @@
+2012-09-14  Jeff Law  <law@xxxxxxxxxx>
+
+	[BZ #14583]
+	* sysdeps/pthread/pthread.h: Fix prototype of __sigsetjmp.
+
 2012-09-13  H.J. Lu  <hongjiu.lu@xxxxxxxxx>
 
 	[BZ #14576]

Modified: fsf/trunk/libc/nptl/sysdeps/pthread/pthread.h
==============================================================================
--- fsf/trunk/libc/nptl/sysdeps/pthread/pthread.h (original)
+++ fsf/trunk/libc/nptl/sysdeps/pthread/pthread.h Sat Sep 15 00:01:40 2012
@@ -731,7 +731,7 @@
 
 /* Function used in the macros.  */
 struct __jmp_buf_tag;
-extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW;
+extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL;
 
 
 /* Mutex handling.  */

Modified: fsf/trunk/libc/stdio-common/Makefile
==============================================================================
--- fsf/trunk/libc/stdio-common/Makefile (original)
+++ fsf/trunk/libc/stdio-common/Makefile Sat Sep 15 00:01:40 2012
@@ -57,7 +57,7 @@
 	 bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \
 	 scanf16 scanf17 tst-setvbuf1 tst-grouping bug23 bug24 \
 	 bug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide tst-sprintf3 \
-	 bug25
+	 bug25 tst-printf-round
 
 test-srcs = tst-unbputc tst-printf
 
@@ -128,3 +128,10 @@
 $(objpfx)tst-setvbuf1.out: tst-setvbuf1.expect $(objpfx)tst-setvbuf1
 	$(built-program-cmd) > $@ 2>&1
 	cmp tst-setvbuf1.expect $@
+
+ifeq ($(build-shared),yes)
+link-libm = $(common-objpfx)math/libm.so
+else
+link-libm = $(common-objpfx)math/libm.a
+endif
+$(objpfx)tst-printf-round: $(link-libm)

Modified: fsf/trunk/libc/stdio-common/printf_fp.c
==============================================================================
--- fsf/trunk/libc/stdio-common/printf_fp.c (original)
+++ fsf/trunk/libc/stdio-common/printf_fp.c Sat Sep 15 00:01:40 2012
@@ -39,6 +39,8 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <wchar.h>
+#include <stdbool.h>
+#include <rounding-mode.h>
 
 #ifdef COMPILE_WPRINTF
 # define CHAR_T        wchar_t
@@ -196,9 +198,6 @@
 
   /* Temporary bignum value.  */
   MPN_VAR(tmp);
-
-  /* Digit which is result of last hack_digit() call.  */
-  wchar_t digit;
 
   /* The type of output format that will be used: 'e'/'E' or 'f'.  */
   int type;
@@ -955,33 +954,30 @@
       }
 
     /* Do rounding.  */
-    digit = hack_digit ();
-    if (digit > L'4')
+    wchar_t last_digit = wcp[-1] != decimalwc ? wcp[-1] : wcp[-2];
+    wchar_t next_digit = hack_digit ();
+    bool more_bits;
+    if (next_digit != L'0' && next_digit != L'5')
+      more_bits = true;
+    else if (fracsize == 1 && frac[0] == 0)
+      /* Rest of the number is zero.  */
+      more_bits = false;
+    else if (scalesize == 0)
+      {
+	/* Here we have to see whether all limbs are zero since no
+	   normalization happened.  */
+	size_t lcnt = fracsize;
+	while (lcnt >= 1 && frac[lcnt - 1] == 0)
+	  --lcnt;
+	more_bits = lcnt > 0;
+      }
+    else
+      more_bits = true;
+    int rounding_mode = get_rounding_mode ();
+    if (round_away (is_neg, (last_digit - L'0') & 1, next_digit >= L'5',
+		    more_bits, rounding_mode))
       {
 	wchar_t *wtp = wcp;
-
-	if (digit == L'5'
-	    && ((*(wcp - 1) != decimalwc && (*(wcp - 1) & 1) == 0)
-		|| ((*(wcp - 1) == decimalwc && (*(wcp - 2) & 1) == 0))))
-	  {
-	    /* This is the critical case.	 */
-	    if (fracsize == 1 && frac[0] == 0)
-	      /* Rest of the number is zero -> round to even.
-		 (IEEE 754-1985 4.1 says this is the default rounding.)  */
-	      goto do_expo;
-	    else if (scalesize == 0)
-	      {
-		/* Here we have to see whether all limbs are zero since no
-		   normalization happened.  */
-		size_t lcnt = fracsize;
-		while (lcnt >= 1 && frac[lcnt - 1] == 0)
-		  --lcnt;
-		if (lcnt == 0)
-		  /* Rest of the number is zero -> round to even.
-		     (IEEE 754-1985 4.1 says this is the default rounding.)  */
-		  goto do_expo;
-	      }
-	  }
 
 	if (fracdig_no > 0)
 	  {
@@ -1076,7 +1072,6 @@
 	  }
       }
 
-  do_expo:
     /* Now remove unnecessary '0' at the end of the string.  */
     while (fracdig_no > fracdig_min + added_zeros && *(wcp - 1) == L'0')
       {

Added: fsf/trunk/libc/stdio-common/tst-printf-round.c
==============================================================================
--- fsf/trunk/libc/stdio-common/tst-printf-round.c (added)
+++ fsf/trunk/libc/stdio-common/tst-printf-round.c Sat Sep 15 00:01:40 2012
@@ -1,0 +1,110 @@
+/* Test for correct rounding of printf floating-point output.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <stdio.h>
+#include <string.h>
+
+struct dec_test {
+  double d;
+  const char *fmt;
+  const char *rd, *rn, *rz, *ru;
+};
+
+static const struct dec_test dec_tests[] = {
+  { 1.5, "%.0f", "1", "2", "1", "2" },
+  { -1.5, "%.0f", "-2", "-2", "-1", "-1" },
+  { 2.5, "%.0f", "2", "2", "2", "3" },
+  { -2.5, "%.0f", "-3", "-2", "-2", "-2" },
+  { 1.4999, "%.0f", "1", "1", "1", "2" },
+  { -1.4999, "%.0f", "-2", "-1", "-1", "-1" },
+  { 1.5001, "%.0f", "1", "2", "1", "2" },
+  { -1.5001, "%.0f", "-2", "-2", "-1", "-1" },
+  { 2.4999, "%.0f", "2", "2", "2", "3" },
+  { -2.4999, "%.0f", "-3", "-2", "-2", "-2" },
+  { 2.5001, "%.0f", "2", "3", "2", "3" },
+  { -2.5001, "%.0f", "-3", "-3", "-2", "-2" },
+  { 1.0 / 3.0, "%f", "0.333333", "0.333333", "0.333333", "0.333334" },
+  { -1.0 / 3.0, "%f", "-0.333334", "-0.333333", "-0.333333", "-0.333333" },
+  { 0.2500001, "%.2e", "2.50e-01", "2.50e-01", "2.50e-01", "2.51e-01" },
+  { -0.2500001, "%.2e", "-2.51e-01", "-2.50e-01", "-2.50e-01", "-2.50e-01" },
+  { 1000001.0, "%.1e", "1.0e+06", "1.0e+06", "1.0e+06", "1.1e+06" },
+  { -1000001.0, "%.1e", "-1.1e+06", "-1.0e+06", "-1.0e+06", "-1.0e+06" },
+};
+
+static int
+test_dec_in_one_mode (double d, const char *fmt, const char *expected,
+		      const char *mode_name)
+{
+  char buf[100];
+  int ret = snprintf (buf, sizeof buf, fmt, d);
+  if (ret <= 0 || ret >= (int) sizeof buf)
+    {
+      printf ("snprintf for %a returned %d\n", d, ret);
+      return 1;
+    }
+  if (strcmp (buf, expected) == 0)
+    return 0;
+  else
+    {
+      printf ("snprintf (\"%s\", %a) returned \"%s\" not \"%s\" (%s)\n",
+	      fmt, d, buf, expected, mode_name);
+      return 1;
+    }
+}
+
+static int
+do_test (void)
+{
+  int save_round_mode = fegetround ();
+  int result = 0;
+
+  for (size_t i = 0; i < sizeof (dec_tests) / sizeof (dec_tests[0]); i++)
+    {
+      result |= test_dec_in_one_mode (dec_tests[i].d, dec_tests[i].fmt,
+				      dec_tests[i].rn, "default rounding mode");
+#ifdef FE_DOWNWARD
+      if (!fesetround (FE_DOWNWARD))
+	{
+	  result |= test_dec_in_one_mode (dec_tests[i].d, dec_tests[i].fmt,
+					  dec_tests[i].rd, "FE_DOWNWARD");
+	  fesetround (save_round_mode);
+	}
+#endif
+#ifdef FE_TOWARDZERO
+      if (!fesetround (FE_TOWARDZERO))
+	{
+	  result |= test_dec_in_one_mode (dec_tests[i].d, dec_tests[i].fmt,
+					  dec_tests[i].rz, "FE_TOWARDZERO");
+	  fesetround (save_round_mode);
+	}
+#endif
+#ifdef FE_UPWARD
+      if (!fesetround (FE_UPWARD))
+	{
+	  result |= test_dec_in_one_mode (dec_tests[i].d, dec_tests[i].fmt,
+					  dec_tests[i].ru, "FE_UPWARD");
+	  fesetround (save_round_mode);
+	}
+#endif
+    }
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"

_______________________________________________
Commits mailing list
Commits@xxxxxxxxxx
http://eglibc.org/cgi-bin/mailman/listinfo/commits