When compiling the attached program with -O0, the program
exits with exit code 0 (echo $?) -- this is OK. When
compiling the attached program with -O2 however, then it
exits with exit code 1 -- this is wrong. I'm not sure
whether this really is a bug in the optimizer or the result
of rounding effects, but it is really something strange.
BTW, when replacing "<" by ">", the problem disappears.
It also looks like the problem only occurs when "step" has
a lot of bits behind the binary point (e.g. 0.1, 0.2 or
0.3, but not 0.5 or 0.25).
both 2.95.3 and 3.0
RedHat Linux 6.1 with 2.4.7 kernel
g++ -O0 -Wall NormalizeFloat.cpp && (./a.out;echo $?)
g++ -O2 -Wall NormalizeFloat.cpp && (./a.out;echo $?)
will give you the output 0 and 1 on separate lines.
Either turn optimization off or put one of the calls to
Normalize() in a separate statement.
State-Changed-Why: See whether -ffloat-store ``fixes'' the problem. If it does, you're being bitten by the excess precision in x86's FP registers.
State-Changed-Why: Reported confirmed that the difference was caused by excess precision.
Reopening bug to mark bug as a dup of bug 323 so ...
that the number of dup of that bug goes up.
*** This bug has been marked as a duplicate of 323 ***