Alan G Isaac wrote:
On Thu, 25 May 2006, Robert Kern apparently wrote:
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.
Just to be clear, I meant not (!) to presumptuosly propose a method for improving thigs, but just to illustrate the issue: both the loss of accuracy, and the obvious conceptual point that there is (in an abstract sense, at least) no need for sin(x) and sin(x+ 2*pi) to differ.
But numpy doesn't deal with abstract senses. It deals with concrete floating point arithmetic. The best value you can *use* for pi in that expression is not the real irrational π. And the best floating-point algorithm you can use for sin() won't (and shouldn't!) assume that sin(x) will equal sin(x + 2*pi).
That your demonstration results in the desired exact 0.0 for multiples of 2*pi is an accident. The results for values other than integer multiples of pi will be as wrong or more wrong. It does not demonstrate that floating-point sin(x) and sin(x + 2*pi) need not differ.