
Boost : 
Subject: Re: [boost] [serialization] How are floating point values handled?
From: John Maddock (john_at_[hidden])
Date: 20130808 07:01:16
>> Hmmm  that surprises me. I look at the code in the file
>> basic_text_oprimitive.hpp and I find:
>>
>> void save(const float t)
>> {
>> // must be a user mistake  can't serialize uninitialized data
>> if(os.fail())
>> boost::serialization::throw_exception(
>> archive_exception(archive_exception::output_stream_error)
>> );
>> os << std::setprecision(std::numeric_limits<float>::digits10 + 2);
>> os << t;
>> }
>>
>> Is this code not correct? Note that I added in 2 extra digits. Or
>> is this code not getting invoked? Let me know.
Ah, I think there are still 2 bugs:
* There's no special handling for long double  so it gets the default 5
digits.
* You don't output in scientific format: what that means in practice is that
if you write a number with a small exponent and it gets printed in fixed
format, then you get std::numeric_limits<float>::digits10 + 2 digits *after
the decimal point*. That may be too many digits if the exponent is > 0, but
if the exponent is < 0 then you get fewer *significant* digits printed than
you might expect, as the number will be 0.001234.... etc
And of course there's still no way to set the number of digits on UDT's
declared as primitives.
John.
PS would it be OK to apply the patch from
https://svn.boost.org/trac/boost/ticket/8963 ?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk