Re: silly Math question from Fortran programmer
LC's No-Spam Newsreading account <nospam@mi.iasf.cnr.it> writes:
I am a scientist with a background in Fortran programming which
occasionally works in Java. I recently had the need to make
some trigonometric computations
That is a good choice, because Java takes special care
to give correct results.
?x87 fsin/fcos use a particular approximation to pi, which
effectively means the period of the function is changed,
which can lead to large errors outside [-pi/4, pi/4]. [...]
instead of getting the full 15-17 digit accuracy of
double, the returned result is only correct to about 5
decimal digits. In terms of ulps, the error is about
1.64e11 ulps, over *ten billion* ulps. [...]
What we do in the JVM on x86 is moderately obvious: we
range check the argument, and if it's outside the range
[-pi/4, pi/4] we do the precise range reduction by hand,
and then call fsin. So Java is accurate, but slower.?
http://blogs.sun.com/jag/entry/transcendental_meditation