i've asked a similar question to this in the past, but the example i gave

was not good enough i think to warrant any good answers... so i've come up

with another example that should be clear.

consider a loop that adds some values from an array of doubles x... such

as (where "a" is a constant value):

for(int i = 0; i < x.length; i++)

result += (x[i] - a) / x.length;

now, one can also obviously do:

for(int i = 0; i < x.length; i++)

result += (x[i] - a);

result = result / x.length;

if the code is executed directly as it is written, the second version can

be far more efficient (only one division, vs x.length divisions)... and

let us assume that precision is not a direct concern at the moment.

does anyone know if the java compiler will attempt to see this

optimization and make the appropriate change if the code is given as it is

in the first example?

thanks much,

murat

--

Murat Tasan

mx**@po.cwru.edu ta***@eecs.cwru.edu mu*********@cwru.edu http://genomics.cwru.edu