|
|
|
|
|
by bnegreve
2758 days ago
|
|
> However, the compiler ('s optimization step) is not magic and produces suboptimal code sometimes. I agree that compilers are not always perfect, but in this particular case the two expressions are trivially equivalent from the associativity of the multiplication so the distinction had to be intentional. But as gnuvince pointed out, the two expressions are not equivalent when you consider integer overflow. |
|
<smallest possible positive number> * 0.5 * 2
When evaluated like that:
(<SPPN> * 0.5) * 2
the result is 0 * 2 = 0
And when evaluated the other way around:
<SPPN> * (0.5 * 2)
the result is <SPPN> * 1 = <SPPN>