This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/9151


Hi,

tested x86-linux, approved by Benjamin, committed.

Paolo.

////////////
2003-01-06  Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/9151
	* include/bits/locale_facets.cc (num_put::_M_convert_float):
	Limit __prec to digits10 + 2, not digits10 + 1, taking into
	account the possibility of %{g,G} conversion specifiers
	inside _S_format_float.
	* testsuite/27_io/ostream_inserter_arith.cc (test06): Add.
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2002-12-16 19:22:58.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc	2003-01-06 16:08:50.000000000 +0100
@@ -622,9 +622,14 @@
       _M_convert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
 		       _ValueT __v) const
       {
-	// Note: digits10 is rounded down.  We need to add 1 to ensure
+	// Note: digits10 is rounded down: we need to add 1 to ensure
 	// we get the full available precision.
-	const int __max_digits = numeric_limits<_ValueT>::digits10 + 1;
+	// Then, in general, one more 1 needs to be added since, when the
+	// %{g,G} conversion specifiers are chosen inside _S_format_float, the
+	// precision field is "the maximum number of significant digits", *not*
+	// the "number of digits to appear after the decimal point", as happens
+	// for %{e,E,f,F} (C99, 7.19.6.1,4).
+	const int __max_digits = numeric_limits<_ValueT>::digits10 + 2;
 	streamsize __prec = __io.precision();
 
 	if (__prec > static_cast<streamsize>(__max_digits))
diff -urN libstdc++-v3-orig/testsuite/27_io/ostream_inserter_arith.cc libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc
--- libstdc++-v3-orig/testsuite/27_io/ostream_inserter_arith.cc	2002-03-09 03:01:34.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc	2003-01-06 15:38:01.000000000 +0100
@@ -368,7 +368,26 @@
   istringstream istr (sval);
   double d;
   istr >> d;
-  VERIFY (abs(pi-d)/pi < DBL_EPSILON);
+  VERIFY( abs(pi-d)/pi < DBL_EPSILON );
+  return 0;
+}
+
+
+// libstdc++/9151
+int
+test06()
+{
+  int prec = numeric_limits<double>::digits10 + 2;
+  double oval = numeric_limits<double>::min();
+
+  stringstream ostr;
+  ostr.precision(prec);
+  ostr << oval;
+  string sval = ostr.str();
+  istringstream istr (sval);
+  double ival;
+  istr >> ival;
+  VERIFY( abs(oval-ival)/oval < DBL_EPSILON ); 
   return 0;
 }
 
@@ -380,6 +399,7 @@
   test03();
   test04();
   test05();
+  test06();
 #ifdef TEST_NUMPUT_VERBOSE
   cout << "Test passed!" << endl;
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]