It isn't everyday that your code exposes a bug in a C compiler, that too, one which has been around for 7.4 versions. I've been writing code that tests a computer's floating point routines for compliance with IEEE 754 with respect to NaNs, denormals and the REM operation. gcc-2.95 has been my friend on all the various archs that I've tested, except on the SGI workstations, where I'm using the vendor supplied MIPSPro v7.4 compiler.
Now consider:
number != number
What will this condition evaluate to? False always? Right? Hence the compiler simply replaces the above with False (or zero) at compile time.
Except, it gets it wrong when it does the same to float variables. You see, if the float contains a NaN, then the above test is true! NaNs do not compare equal.
Aha! Now where do I report this bug?
Some other "crazy" stuff (called constant foldings, or compile-time evaluations done by GCC):
n * 1.0 => removed, as n is not changed
n / 1.0, likewise
n * 2.0 => n + n
And all of this with optimizations disabled! Wow!
Subscribe to:
Post Comments (Atom)
1 comment:
Hey cool man. BTW please enable your entire post to show up in the feed cos I'm using liferea.
Post a Comment