
On 9/28/2010 1:12 PM, Henry Tan wrote:
Hi I am using boost 1.4.1 Spirit::Qi.
I think we have a floating point truncation bug in the qi::float_ parser. I attached a simple program to repro the bug.
Below are some examples of an input floating point gets truncated (=>) by the qi::float_:
12312321421421 => 12312321720320.000000 123123214 => 123123216.000000 123233.4124 => 123233.406250
I don't see the same issue with the qi::double_.
Wondering if this is a known issue?
Regards,
HTan
Without being too familiar with the qi::float_ parser, I would guess it rounds rather than truncates. Keep in mind that floats are typically 32-bit single precision [1], hence have only 24 significant bits (a bit more than 7 significant decimal digits), which is consistent with your results. On the other hand, doubles are typically 64-bit double precision [2], hence have 53 significant bits (a bit under 16 significant decimal digits), so the first 2 inputs above would be stored exactly, and the 3rd one would be pretty close. - Jeff [1] http://en.wikipedia.org/wiki/Single_precision_floating-point_format [2] http://en.wikipedia.org/wiki/Double_precision_floating-point_format