Boost logo

Boost :

Subject: Re: [boost] Floating point truncation bug in qi::float_
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-09-28 18:11:53


> 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?

If I do:

    #include <iostream>
    #include <iomanip>

    int main()
    {
        float f1 = 12312321421421.f;
        float f2 = 123123214.f;
        float f3 = 123233.4124f;

        std::cout.precision(20);

        std::cout << "12312321421421 --> " << f1 << std::endl;
        std::cout << "123123214 --> " << f2 << std::endl;
        std::cout << "123233.4124 --> " << f3 << std::endl;
        return 0;
    }

I get (gcc 4.5.1 and VS2010):

    12312321421421 --> 12312321720320
    123123214 --> 123123216
    123233.4124 --> 123233.4140625

which is almost consistent with what Spirit is doing. The last case worries me, though. I'll try to have a closer look there.

Regards Hartmut
---------------
http://boost-spirit.com


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