[Numpy-discussion] Re: numpy.sin

Rob Hooft rob at hooft.net
Thu May 25 11:53:06 EDT 2006


-----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  ||  rob at hooft.net  ||  http://www.hooft.net/people/rob/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEdfziH7J/Cv8rb3QRAiO8AKCQdJ+9EMOP6bOmUX0NIhuWVoEFQgCgmvTS
fgO08dI16AUFcYKkpRJXg/Q=
=qQXI
-----END PGP SIGNATURE-----




More information about the NumPy-Discussion mailing list