Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2006-03-14 13:11:07


Paul Giaccone wrote:
> I'm having problems with deserialising floating-point (double) values
> that are written to an XML file. I'm reading the values back in and
> comparing them to what I saved to ensure that my file has been written
> correctly. However, some of the values differ in about the seventeenth
> significant figure (or thereabouts).
>
> I thought Boost serialization used some numerical limit to make sure
> that values are serialised exactly to full precision, so what is
> happening here?

This is a common cause of errors when using floating point values.
Writing a floating point value to a string representation, as are XML
values, and attempting to read that string representation back, does not
guarantee that the floating point value will remain exactly the same
since there are a number of floating point values which have no exact
representation in the C++ floating point formats. That is simply because
of the nature of floating point representation used in C++ and most
modern languages. After all, the number of floating point values within
any range of numbers is infinite while the C++ floating point
representation cab not be. The only way to guarantee what you want for
floating point values is to write and read back to a binary
representation of the value.


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