From 1dedf55c48e490629765e5432aa2267d49542bce Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 22 Feb 2004 17:57:21 +0000 Subject: [PATCH] re PR libstdc++/14220 ([3.5] num_put::do_put() undesired float/double behavior) 2004-02-22 Paolo Carlini PR libstdc++/14220 * include/bits/locale_facets.tcc (num_put<>::_M_convert_float): Don't clip the precision passed down to __convert_from_v: 22.2.2.2.2 nowhere says so. From-SVN: r78268 --- libstdc++-v3/ChangeLog | 7 +++++ libstdc++-v3/include/bits/locale_facets.tcc | 31 ++++++++------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 03f66fa5e690..2bb5a2a2d919 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2004-02-22 Paolo Carlini + + PR libstdc++/14220 + * include/bits/locale_facets.tcc (num_put<>::_M_convert_float): + Don't clip the precision passed down to __convert_from_v: + 22.2.2.2.2 nowhere says so. + 2004-02-14 Release Manager * GCC 3.3.3 Released. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 3dec34ecdaa3..641d333fa8a7 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -884,22 +884,13 @@ namespace std _M_convert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod, _ValueT __v) const { - // Note: digits10 is rounded down: add 1 to ensure the maximum - // available precision. 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; - // Use default precision if out of range. streamsize __prec = __io.precision(); - if (__prec > static_cast(__max_digits)) - __prec = static_cast(__max_digits); - else if (__prec < static_cast(0)) + if (__prec < static_cast(0)) __prec = static_cast(6); + const int __max_digits = numeric_limits<_ValueT>::digits10; + typedef numpunct<_CharT> __facet_type; typedef __locale_cache > __cache_type; const locale __loc = __io._M_getloc(); @@ -911,7 +902,7 @@ namespace std char __fbuf[16]; #ifdef _GLIBCPP_USE_C99 - // First try a buffer perhaps big enough (for sure sufficient + // First try a buffer perhaps big enough (most probably sufficient // for non-ios_base::fixed outputs) int __cs_size = __max_digits * 3; char* __cs = static_cast(__builtin_alloca(__cs_size)); @@ -933,13 +924,13 @@ namespace std const bool __fixed = __io.flags() & ios_base::fixed; const int __max_exp = numeric_limits<_ValueT>::max_exponent10; - // ios_base::fixed outputs may need up to __max_exp+1 chars - // for the integer part + up to __max_digits chars for the - // fractional part + 3 chars for sign, decimal point, '\0'. On - // the other hand, for non-fixed outputs __max_digits*3 chars - // are largely sufficient. - const int __cs_size = __fixed ? __max_exp + __max_digits + 4 - : __max_digits * 3; + // ios_base::fixed outputs may need up to __max_exp + 1 chars + // for the integer part + __prec chars for the fractional part + // + 3 chars for sign, decimal point, '\0'. On the other hand, + // for non-fixed outputs __max_digits * 2 chars + __prec are + // largely sufficient. + const int __cs_size = __fixed ? __max_exp + __prec + 4 + : __max_digits * 2 + __prec; char* __cs = static_cast(__builtin_alloca(__cs_size)); _S_format_float(__io, __fbuf, __mod, __prec); -- 2.47.2