The produced value is not the expected.

The code:

#include <iostream>
#include <limits>

int main()
{
    using namespace std;

    long double x= numeric_limits<unsigned long>::max();

    cout<< fixed;

    for(unsigned i= 0; i< 10; ++i)
    {
        cout<< x<< endl;
        ++x;
    }

    cout<< endl<< x<< endl<< numeric_limits<unsigned long>::max()<< endl;
}


It produces:

j...@john-laptop:~/Projects/anjuta/cpp/src$ g++ -ansi -pedantic-errors -Wall
main.cc -o foobar 
j...@john-laptop:~/Projects/anjuta/cpp/src$ ./foobar 
18446744073709551615.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000
18446744073709551616.000000

18446744073709551616.000000
18446744073709551615
j...@john-laptop:~/Projects/anjuta/cpp/src$


-- 
           Summary: Value increment problems
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ivranos at freemail dot gr
 GCC build triplet: Ubuntu Linux Desktop Edition 9.04 x64
  GCC host triplet: Ubuntu Linux Desktop Edition 9.04 x64
GCC target triplet: Ubuntu Linux Desktop Edition 9.04 x64 ("Target: x86_64-
                    linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40407

Reply via email to