FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-b105, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux hssa1.aoa.twosigma.com 2.6.18-ts1 #1 SMP PREEMPT Fri Sep 29 14:06:04 GMT 2006 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
successive invocations of Math.log() produce inconsistent results (possibly depending on compilation because -Xint or -XX:CompleThreshold=0 always produces consistent results). The number of iterations in the actual result varies.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
$ javac LogTest.java
$ java -cp . LogTest
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
n=17197.0
SUCCESS!
ACTUAL -
n=17197.0
ERROR after 43235 iterations:
previous value: 9.7524902289842 (40238146663817e8)
current value: 9.752490228984199 (40238146663817e7)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class LogTest {
public static void main(String[] args)
{
double n = Integer.parseInt("17197");
System.out.println("n=" + n);
double d = Math.log(n);
for (int i = 0; i < 100000; i++) {
double e = Math.log(n);
if (e != d) {
System.err.println("ERROR after " + i + " iterations:\n" +
"previous value: " + d + " (" +
Long.toHexString(Double.doubleToLongBits(d)) + ")\n" +
" current value: " + e + " (" +
Long.toHexString(Double.doubleToLongBits(e)) + ")");
System.exit(1);
}
}
System.err.println("SUCCESS!");
System.exit(0);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
run with -Xint -XXCompilerThreshold=0 produces the expected result, on the other hand, is that a complete fix? Are floating point results reliable?