Does any floating point-intensive code produce bit-exact results in any x86-based architecture?

Table of contents: C/C++ asm Creating real-life software that achieves this. In C or C++: No, a fully ISO C11 and IEEE-conforming C implementation does not guarantee bit-identical results to other C implementations, even other implementations on the same hardware. (And first of all, I’m going to assume we’re talking about normal C implementations where … Read more

What does gcc’s ffast-math actually do?

-ffast-math does a lot more than just break strict IEEE compliance. First of all, of course, it does break strict IEEE compliance, allowing e.g. the reordering of instructions to something which is mathematically the same (ideally) but not exactly the same in floating point. Second, it disables setting errno after single-instruction math functions, which means … Read more

Why doesn’t GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?

Because Floating Point Math is not Associative. The way you group the operands in floating point multiplication has an effect on the numerical accuracy of the answer. As a result, most compilers are very conservative about reordering floating point calculations unless they can be sure that the answer will stay the same, or unless you … Read more