Will the compiler optimize repeated math computations?
<p>Will the Java Compiler optimize simple repeated math operations like:</p>

<pre><code>if (prevX / width != curX / width) {
    // Do something with prevX / width value
} else {
    // Do something with curX / width value
}
</code></pre>

<p>I know I can just assign the results to a variables before the if statement, and return the variables, but it's kind of cumbersome. If the compiler automatically recognizes that the same calculations are being made and caches the results to temporary variables on its own, I'd rather stick to the above convention.</p>

<p>*Edit - I'm an idiot. I tried to simply/abstract my question too much. It's not at simple as: if (x > y)</p>
