Boost logo

Boost :

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:
> http://boost.2283326.n4.nabble.com/serialization-Serialisation-deserialisation-of-floating-point-values-td2604169i20.html

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,
for
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
work.
That is, the streams i/o attampts to preserve values (rather than bit
representation
) to the extent that it makes sense to do so.

d) It gets much worse with floating point values such as NaN - since
different
libraries differ on how to address this.

e) Remember, this is not a serialization library issue-- but rather one
related
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
floating
point - use something else.

Robert Ramey

> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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