c++/5060: Comparisons between double on gcc 2.96

rodrigc@gcc.gnu.org rodrigc@gcc.gnu.org
Mon Dec 10 12:11:00 GMT 2001


Synopsis: Comparisons between double on gcc 2.96

State-Changed-From-To: open->analyzed
State-Changed-By: rodrigc
State-Changed-When: Mon Dec 10 11:43:54 2001
State-Changed-Why:
    Reproduced with gcc 3.0 and gcc 3.1 on Linux on x86.
    
    The problem goes away if I change your testcase to:
    
    #include <cstddef>
    #include <iostream>
    #include <cstdio>
    using namespace std;
     
    int main()
    {
       double x = 0.0 ;
       std::cout << "Testing floating point behaviour" << std::endl ;
       for( double i=1 ; i<10 ; i++ )
       {
          double z = 1.0/i ;
          double o_x = x ;
          x = x + z ;
          printf("i:%g %20.20g %20.20g   ", i, z+ o_x, x);
          double q = o_x+z;
          //if( ! (x==(double)(o_x+z))) std::cout <<"HELP!";
          if( ! (x==q)) std::cout <<"HELP!";
          std::cout << std::endl;
     
       }
     
    }

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=5060&database=gcc



More information about the Gcc-bugs mailing list