_M_convert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
_ValueT __v) const
{
- const int __max_digits = numeric_limits<_ValueT>::digits10;
+ // 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<streamsize>(__max_digits))
// 1999-11-15 Kevin Ediger <kediger@licor.com>
// test the floating point inserters (facet num_put)
-// Copyright (C) 1999 Free Software Foundation, Inc.
+// Copyright (C) 1999, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// USA.
#include <cstdio> // for sprintf
+#include <cmath> // for abs
+#include <cfloat> // for DBL_EPSILON
#include <iostream>
#include <iomanip>
#include <locale>
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()
{
test02();
test03();
test04();
+ test05();
#ifdef TEST_NUMPUT_VERBOSE
cout << "Test passed!" << endl;
#endif