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-10 17:38:59
#10639: lexical_cast<double>(string) wrong in C++11
--------------------------------+--------------------------
Reporter: richard.kreckel@⦠| Owner: apolukhin
Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
Version: Boost 1.56.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------+--------------------------
Changes (by johnmaddock):
* cc: pbristow@⦠(added)
Comment:
I had a quick look at this, and can confirm the issue - I'm really pretty
surprised to see that the code is parsing the number itself rather than
relying on std::num_get or whatever. Here's the thing: you absolutely
cannot do this correctly (base 10 to 2 conversion) without arbitrary
precision arithmetic - indeed in the worst case there is basically no
limit to how many digits you may need in order to carry out the conversion
correctly (though such cases are extremely rare, as in they will never
ever occur in practice!). In fact getting this right is really bloody
hard - Boost.Multiprecision has an algorithm under
boost/multiprecision/cpp_bin_float/io.hpp based on MPFR's largely brute
force approach, but honestly I wouldn't use that either for convert-to-
built-in-type. There's more information at
http://www.exploringbinary.com/real-c-rounding-is-perfect-gcc-now-
converts-correctly/ which shows that even many respected std lib's often
don't get this right in certain cases. I'm adding Paul Bristow to the CC
list, as I know he has an interest in this.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/10639#comment:1> 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