|
Boost : |
Subject: Re: [boost] [serialization] How are floating point values handled?
From: John Maddock (john_at_[hidden])
Date: 2013-08-08 04:32:49
>> The current
>> default situation is to print just 5 digits, and that certainly
>> doesn't get close!
>
> 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 un-initialized 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... my problem was with a UDT that was marked as a primitive: then it just
calls the << operator and doesn't attempt to set the stream precision as far
as I can tell?
The issue would presumably also surface if someone tried to non-intrusively
support non-standard native floating point types such as GCC's __float128 or
Intel's _Quad data types, you can write a "serialize" function instead, but
as you already pointed out, that involves more typing once you you split the
method into load/save and binary/text variants.
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk