optimization/9736: same fp comparison can lead to different results

richard@wetafx.co.nz richard@wetafx.co.nz
Mon Feb 17 23:16:00 GMT 2003

>Number:         9736
>Category:       optimization
>Synopsis:       same fp comparison can lead to different results
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 17 23:16:00 UTC 2003
>Originator:     richard@wetafx.co.nz
>Release:        g++3 (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Linux 2.4.18-xfssmp #1 SMP i686
void access(const float&) {}
int test(float t)
  float v = 0.75f+t;
  int test1 = v < 1.0f ? 1 : 2;
  int test2 = v < 1.0f ? 1 : 2;
  return test1*10+test2;
int main(void) { return test(0.25f-1.0f/67108864.0f); }
bug: bug.cc; g++3 -O1 -o bug bug.cc
With the two specified files, use gmake to build.

With -O1, the values computed for test1 and test2
are different while the source code is identical.
Can use the -ffloat-store option, but that is a mighty
big hammer.

More information about the Gcc-bugs mailing list