-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Robert Kern wrote: | Alan G Isaac wrote: | |>I am a user, not a numerics type, |>so this is undoubtedly a naive question. |> |>Might the sin function be written to give greater |>accuracy for large real numbers? It seems that significant |>digits are in some sense being discarded needlessly. | | | Not really. The floating point representation of pi is not exact. The problem | only gets worse when you multiply it with something. The method you showed of | using % (2*pi) is only accurate when the values are created by multiplying the | same pi by another value. Otherwise, it just introduces another source of error, | I think. | | This is one of the few places where a version of trig functions that directly | operate on degrees are preferred. 360.0*n is exactly representable by floating | point arithmetic until n~=12509998964918 (give or take a power of two). Doing % | 360 can be done exactly.
This reminds me of a story Richard Feynman tells in his autobiography. He used to say: "if you can pose a mathematical question in 10 seconds, I can solve it with 10% accuracy in one minute just calculating in my head". This worked for a long time, until someone told him "please calculate the sine of a million".
Actual mantissa bits are used by the multiple of two-pi, and those are lost at the back of the calculated value. Calculating the sine of a million with the same precision as the sine of zero requires 20 more bits of accuracy.
Rob - -- Rob W.W. Hooft || firstname.lastname@example.org || http://www.hooft.net/people/rob/