[Numpy-discussion] what goes wrong with cos(), sin()
Wed Feb 21 12:26:39 CST 2007
> I'm quite new to numpy/scipy so please excuse if my problem is too obvious.
> example code:
> import numpy as n
> print n.sin(n.pi)
> print n.cos(n.pi/2.0)
> results in:
> I've expected something around 0. Can anybody explain what I am doing
> wrong here?
Nothing. You are getting something around 0 to the limit of double-precision
floating point. numpy.pi cannot be exactly π, but within about 1e-16 of it. That
imprecision carries through the computations.
"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