Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] Assumed internal double conversion of float?
From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2019-01-29 21:29:39

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.


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.


-----Original Message-----
From: Boost <boost-bounces_at_[hidden]> On Behalf Of Peter Dimov via Boost
Sent: Tuesday, January 29, 2019 9:42 AM
To: boost_at_[hidden]
Cc: Peter Dimov <lists_at_[hidden]>
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:;;sdata=mXgKJMlGxrXod%2BSb8A3HX4F1rFByOZNGZnN4NpeII3w%3D&amp;reserved=0

Boost list run by bdawes at, gregod at, cpdaniel at, john at