Subject: Re: [boost] [serialization] round-trip serialization of float
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-01-10 11:28:21
Adam Lerer wrote:
> Note: There's some discussion of this topic in a slightly different
> context here:
Remember that the serialization library uses standard i/o for input/output.
So this discussion above
is actually the same issue.
In general, libraries won't guarentee bit for bit equality. This is due to
a number of reasons:
a) not every binary floating number has en exact representation when
rendered as decimal.
b) different libraries can't be expected to handle this in all the same way.
c) text type archives are meant to be portable between architectures. So,
example, on can create floating point numbers in an environment which uses
an 80 ieee754 representation, write them to a file, and read them on another
architecture - say a 64 bit ieee754 representation and expect things to
That is, the streams i/o attampts to preserve values (rather than bit
) to the extent that it makes sense to do so.
d) It gets much worse with floating point values such as NaN - since
libraries differ on how to address this.
e) Remember, this is not a serialization library issue-- but rather one
to floating point numbers and standard i/o. i
So, If you feel you need to preserver the exact set of bits - don't use
point - use something else.
> Unsubscribe & other changes:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk