Re: [Boost-bugs] [Boost C++ Libraries] #10639: lexical_cast<double>(string) wrong in C++11

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10639: lexical_cast<double>(string) wrong in C++11
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-10-11 10:37:09


#10639: lexical_cast<double>(string) wrong in C++11
--------------------------------+--------------------------
  Reporter: richard.kreckel@… | Owner: apolukhin
      Type: Bugs | Status: assigned
 Milestone: To Be Determined | Component: lexical_cast
   Version: Boost 1.56.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------+--------------------------

Comment (by johnmaddock):

 Given:

 {{{
 const wide_result_t result = std::pow(static_cast<wide_result_t>(10.0),
 pow_of_10) * mantissa;
 }}}

 Then you have two floating point operations - which is to say, even if
 std::pow is accurate to 0.5ulp, and the multiplication likewise, you can
 still be wrong to 1ulp in the final result. Note that this is true even
 if long double is wider than double due to the "double rounding" problem:
 http://www.exploringbinary.com/double-rounding-errors-in-floating-point-
 conversions/.

 You are correct that your code is the same in C++03 and C++11 modes which
 makes me wonder what's changed - my guess is that because of the issues
 outlined above, your code will be very susceptible to choice of floating-
 point registers used, and/or the level of compiler optimization used.
 Which is to say, the compiler only has to output slightly different code
 at the machine level, and stuff which worked before - largely by accident
 - will now break.

 Fun isn't it? ;-)

 HTH, John.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10639#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC