Subject: Re: [boost] [serialization]Double rounding bug?
From: Ulrich Eckhardt (doomster_at_[hidden])
Date: 2009-10-02 03:53:43
On Thursday 01 October 2009 21:09:00 Mariusz Kwiczala wrote:
> DoubleValue doubleValue1;
> doubleValue1.m_value = -0.0070850229047457131;
> SaveDoubleValue(doubleValue1, "DoubleValue.xml");
> DoubleValue doubleValue2;
> LoadDoubleValue(doubleValue2, "DoubleValue.xml");
> //but from file is read -0.007085022904745714
That value would require between 50 and 60 bits of precision, provided its
representation is actually possible in a binary floating point number. Typical
double-precision floating point numbers have a fraction of 52 bits, so the
changes you are reporting are actually to be expected.
FYI: The estimate above is that three decimal digits (0-999) are roughly
equivalent to ten binary digits (aka bits, decimal 0-1024). You also mention
that the difference occurs to numbers with 19-20 digits behind the dot, but
that is irrelevant. The important part is the number of significant digits,
i.e. the number of digits that are required for the digits without leading and
trailing zeroes regardless of whether they are before or after the dot.
See also: http://www.validlab.com/goldberg/paper.pdf
Note that this would have been better suited to the users' not the developers'