From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3428 invoked by alias); 8 Mar 2002 20:16:08 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3353 invoked by uid 71); 8 Mar 2002 20:16:06 -0000 Date: Fri, 08 Mar 2002 12:16:00 -0000 Message-ID: <20020308201605.3342.qmail@sources.redhat.com> To: paolo@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Scott Snyder Subject: Re: libstdc++/5875: operator<<(double) doesn't allow printing full precision (3.0 regression) Reply-To: Scott Snyder X-SW-Source: 2002-03/txt/msg00282.txt.bz2 List-Id: The following reply was made to PR libstdc++/5875; it has been noted by GNATS. From: Scott Snyder To: paolo@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-gnats@gcc.gnu.org Cc: Subject: Re: libstdc++/5875: operator<<(double) doesn't allow printing full precision (3.0 regression) Date: 08 Mar 2002 14:09:01 -0600 > I think your analysis is correct (as it was the first time, > by the way ;-) and I would suggest posting directly the > patch in the libstdc++ list. However, if you want to > provide a testcase, you should do this as a patch against > the concerned testsuite file, in the standard form based on > the use of VERIFY, portable (this is the tricky point) > across archs characterized by different machine precisions. > I mean, do you think it would be safe testing: > VERIFY(d - pi == 0.0) ?? > I don't think so. What do you suggest then? Oops --- i see i forgot to include the testsuite patch. Here's the full patch again. I tried to ensure that they were equal to within a relative error of DBL_EPSILON --- it may be that that's a little bit too small though. I admit that as of this point, i've only tested it on linux/i86. sss 2002-03-06 scott snyder * include/bits/locale_facets.tcc (num_put::_M_convert_float): Allow one more digit of precision. * testsuite/27_io/ostream_inserter_arith.cc: Test that we can write a double and read back in the same value. Index: include/bits/locale_facets.tcc =================================================================== RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/locale_facets.tcc,v retrieving revision 1.63.2.3 diff -u -p -c -r1.63.2.3 locale_facets.tcc *** locale_facets.tcc 2002/03/05 19:05:05 1.63.2.3 --- locale_facets.tcc 2002/03/08 19:52:00 *************** namespace std *** 610,616 **** _M_convert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod, _ValueT __v) const { ! const int __max_digits = numeric_limits<_ValueT>::digits10; streamsize __prec = __io.precision(); // Protect against sprintf() buffer overflows. if (__prec > static_cast(__max_digits)) --- 610,618 ---- _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 ! // we get the full available precision. ! const int __max_digits = numeric_limits<_ValueT>::digits10 + 1; streamsize __prec = __io.precision(); // Protect against sprintf() buffer overflows. if (__prec > static_cast(__max_digits)) Index: testsuite/27_io/ostream_inserter_arith.cc =================================================================== RCS file: /cvs/gcc/egcs/libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc,v retrieving revision 1.15 diff -u -p -c -r1.15 ostream_inserter_arith.cc *** ostream_inserter_arith.cc 2002/01/31 00:03:31 1.15 --- ostream_inserter_arith.cc 2002/03/08 19:51:23 *************** *** 20,25 **** --- 20,27 ---- // USA. #include // for sprintf + #include // for abs + #include // for DBL_EPSILON #include #include #include *************** test04() *** 355,360 **** --- 357,377 ---- return 0; } + int + test05() + { + double pi = 3.14159265358979323846; + ostringstream ostr; + ostr.precision(20); + ostr << pi; + string sval = ostr.str(); + istringstream istr (sval); + double d; + istr >> d; + VERIFY (abs(pi-d)/pi < DBL_EPSILON); + return 0; + } + int main() { *************** main() *** 362,367 **** --- 379,385 ---- test02(); test03(); test04(); + test05(); #ifdef TEST_NUMPUT_VERBOSE cout << "Test passed!" << endl; #endif