On Mar 4, 9:05 am, Sanny <softta...@hotmail.com> wrote:
On Mar 4, 6:29 pm, Patricia Shanahan <p...@acm.org> wrote:
Sanny wrote:
On Mar 4, 3:40 pm, Steve70 <batst...@libero.it> wrote:
I must create a program that use trigonometry function.
I know sin(30)=0.5 but when I use Math.sin() I can't get it
Math.sin(30*Math.PI/180)=0.49999999999999994
What's the problem?
Thank you
Stefano Buscherini
Math.sin uses Log tables to calculate value of Sin So they are
approximate to 0.0000000000001 Value.
I'm curious. Why log tables?
I don't know how Math.sin is implemented, and don't even assume it is
implemented the same way in all JVMs, but if I had to guess I would have
expected some sort of truncated Taylor series.
Patricia
Using Tables are faster than using a formula to compute a value.
By log table I just mean a Table for Sine. Log tables are more
familiar than Log Tables.
Bye
Sanny
Looking at the flibdm libraries, whose algorithms are used in Sun's
JVM's, and which define the results that must be given when strictmath
is specified, the sine function consists of a range reduction such
that only the range 0 to pi/4 need be considered, followed by a
polynomial expansion to 13th order. I didn't check to see if this is
simply the Taylor expansion as Patricia suggested. It's possible that
some slight modification has better error properties. Since only odd
terms need be considered this takes relatively few operations ~ 7
additions and multiplications. It's small enough that the overhead of
the function call is probably a non-trivial fraction of the total
cost.
That's about what I would have guessed. Thanks for the information.