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
>Closed-Date:
>Last-Modified:
>Originator: richard@wetafx.co.nz
>Release: g++3 (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
>Organization:
>Environment:
Linux 2.4.18-xfssmp #1 SMP i686
>Description:
//////////bug.cc:
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;
access(v);
return test1*10+test2;
}
int main(void) { return test(0.25f-1.0f/67108864.0f); }
//////////GNUmakefile
bug: bug.cc; g++3 -O1 -o bug bug.cc
>How-To-Repeat:
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.
>Fix:
Can use the -ffloat-store option, but that is a mighty
big hammer.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list