[Numpy-discussion] Re: numpy.sin

Robert Kern robert.kern at gmail.com
Thu May 25 11:37:09 EDT 2006


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.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco





More information about the NumPy-Discussion mailing list