Boost logo

Boost :

Subject: Re: [boost] [serialization] round-trip serialization of float
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-01-11 15:45:53


Adam Lerer wrote:
>>> a) not every binary floating number has en exact representation when
>>> rendered as decimal.
> True, but if max_digits10 digits is used, you can at least guarantee
> that the binary representation will deserialize as the same float.
> This is very helpful for common use cases of the serialization library
>
> I understand that float serialization cannot be guaranteed to work
> correctly in all cases. That said, the precision used for float
> serialization is a choice, and some choices are better than others. It
> seems to me that the choice of max_digits10 (or even better, Paul's
> alternative formula to work around the VS bug) is superior to
> digits10+2.
>
> It might also be helpful to note that lexical_cast uses exactly the
> formula that Paul recommends. In lcast_precision.hpp:
>
> BOOST_STATIC_CONSTANT(unsigned long, precision_bin =
> 2UL + limits::digits * 30103UL / 100000UL
> );
>

Feel free to add a trac item for this

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk