After upgrading to gcc 4.5.0 from 3.3.4, some of my floating point code fails. 
Searched for and could not find a matching bug.  It boils down to this very
simple example:

#include <stdio.h>

#define MY_PI   3.14159265358979323846

int main()
    double z = MY_PI;
    puts(z == MY_PI ? "==" : "!=");
    return 0;

If this is compiled "gcc -o bug -Wall bug.c" it works: there is equality. 
Doesn't matter if optimization is used or not (-g, -O, -O2 all give same

But if compiled with -ansi or -std=c99, then the equality fails, again
regardless of optimization!!

The preprocessed code looks as expected:

int main()
    double z = 3.14159265358979323846;
    puts(z == 3.14159265358979323846 ? "==" : "!=");
    return 0;

Cannot see how this is correct behavior since the exact same expression was
used to initialize the variable and to test for equality.  Do not see anything
in my ANSI/ISO C reference that sheds any light.

I can work around this by using actual double constants instead of preprocessor
expressions ("double my_pi_2 = MY_PI_2" and setting/testing with my_pi_2, etc),
but this should work as is!

           Summary: Floating point comparison failure
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at macky dot net

Reply via email to