problem with the 'math' module in 2.5?
carsten at uniqsys.com
Sun Oct 15 06:18:29 CEST 2006
On 14 Oct 2006 20:33:13 -0700, Chris wrote
> >>> from math import *
> >>> sin(0)
> >>> sin(pi)
> >>> sin(2*pi)
> >>> cos(0)
> >>> cos(pi)
> >>> cos(2*pi)
> The cosine function works fine, but I'm getting weird answers for sine.
> Is this a bug? Am I doing something wrong?
You're apparently not correctly reading python's answer to sin(pi).
1.2246063538223773e-016 is the scientific notation for the number
0.00000000000000012246063538223773, which is pretty darn close to zero, the
result you probably expected.
You're not getting *exactly* zero because you're not passing in *exactly* pi
but a close approximation of pi.
I'll leave it as an exercise for the reader to explain why cosine seems to
work fine. Hint: Look at cos(pi/2) and sin(pi/2).
More information about the Python-list