
Note that there are two numbers of digits that are of interest: If you take a decimal number, convert it to float, and convert it back to decimal, how many decimal digits are guaranteed to survive unchanged? If you take a float, convert it to decimal, and convert it back to float, how many decimal digits are required to always get all bits of the original float correct? For 32-bit float, the answers are 6 and 9, respectively. For 64-bit double, it's 15 and 17. See: https://www.exploringbinary.com/number-of-digits-required-for-round-trip-con... As an aside: when converting a string to a floating-point number, it is incorrect to round twice - i.e. you cannot implement strtof by calling strtod and then rounding double to float. STL -----Original Message----- From: Boost <boost-bounces@lists.boost.org> On Behalf Of Peter Dimov via Boost Sent: Tuesday, January 29, 2019 9:42 AM To: boost@lists.boost.org Cc: Peter Dimov <lists@pdimov.com> Subject: Re: [boost] [lexical_cast] Assumed internal double conversion of float? Brian Kuhl wrote:
Where does boost::detail::lcast_get_precision<float>() come from, and why is it 9 ? Is it perhaps assuming some intermediate double conversion internally?
boost::detail::lcast_get_precision<double>() is 17, so no. My guess is that this is the precision that guarantees a perfect roundtrip. _______________________________________________ Unsubscribe & other changes: https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.boost...