4 ms·
Compiler optimization.
by creeble 4y ago
Compiler optimization.
- lifthrasiir 4y agoCompilers are very cautious about floating point optimization because many real number identities do not hold in FP, so they won't do much unless instructed to do so. Even if they do a constant propagation they will generally calculate in binary, in decimal. (Exception: decimal literals in some languages like Go are untyped and can be exactly calculated before getting rounded at once.)
- kazinator 4y agoWrong guess; the algebraic optimization you might be thinking of is simply not allowed. The expression is likely subject to an optimization known as constant folding: the compiler calculates the value of the constant expression, and substitutes that value into the code. However, that constant-folding calculation has to produce the same result as what would happen at run-time: the 56.999999999999992895... approximation of 57. Constant-folding having to produce the same results as run-time creates a challenge in cross-compiling situations, when the host machine's math is different from the target machine's math. The compiler must emulate the target machine math.
- creeble 4y agoI guess I'm misunderstanding what `-frounding-math` for gcc does / does not do.