Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-22 Thread David M. Cooke
On Feb 21, 2007, at 14:54 , Christopher Barker wrote: > Anne Archibald wrote: >> Or, to see more clearly, try taking (on a pocket calculator, say) >> sin(3.14) (or even sin(pi)). > > This is an interesting point. I took a class from William Kahan once > (pass/fail, thank god!), and one question he

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-22 Thread Christopher Barker
David L Goldsmith wrote: > I agree w/ Chuck - I'd consider what Tim describes is happening a "bug". It's not a bug, but it is a missing feature. numpy doesn't appear to convert strings to numbers for any of its own types: >>> N.float128("4.3") Traceback (most recent call last): File "", line

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-22 Thread David L Goldsmith
I agree w/ Chuck - I'd consider what Tim describes is happening a "bug". DG Charles R Harris wrote: > > > On 2/21/07, *Timothy Hochberg* <[EMAIL PROTECTED] > > wrote: > > > > On 2/21/07, *Charles R Harris* < [EMAIL PROTECTED] > > wrote:

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Charles R Harris
On 2/21/07, Charles R Harris <[EMAIL PROTECTED]> wrote: On 2/21/07, Timothy Hochberg <[EMAIL PROTECTED]> wrote: > > > > On 2/21/07, Charles R Harris < [EMAIL PROTECTED]> wrote: > > > > > > > > On 2/21/07, Robert Kern < [EMAIL PROTECTED]> wrote: > > > > > > Christopher Barker wrote: > > > > Rob

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Charles R Harris
On 2/21/07, Timothy Hochberg <[EMAIL PROTECTED]> wrote: On 2/21/07, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > > On 2/21/07, Robert Kern < [EMAIL PROTECTED]> wrote: > > > > Christopher Barker wrote: > > > Robert Kern wrote: > > >> Christopher Barker wrote: > > >>> I wonder if there are

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Timothy Hochberg
On 2/21/07, Charles R Harris <[EMAIL PROTECTED]> wrote: On 2/21/07, Robert Kern <[EMAIL PROTECTED]> wrote: > > Christopher Barker wrote: > > Robert Kern wrote: > >> Christopher Barker wrote: > >>> I wonder if there are any C math libs that do a better job than > you'd > >>> expect from standar

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Charles R Harris
On 2/21/07, Robert Kern <[EMAIL PROTECTED]> wrote: Christopher Barker wrote: > Robert Kern wrote: >> Christopher Barker wrote: >>> I wonder if there are any C math libs that do a better job than you'd >>> expect from standard FP? (short of unlimited precision ones) >> With respect to π and the z

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Anne Archibald
On 21/02/07, Robert Kern <[EMAIL PROTECTED]> wrote: > Well, you can always use long double if it is implemented on your platform. > You > will have to construct a value for π yourself, though. I'm afraid that we > don't > really make that easy. If the trig functions are implemented at all, you

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Robert Kern
Christopher Barker wrote: > Robert Kern wrote: >> Christopher Barker wrote: >>> I wonder if there are any C math libs that do a better job than you'd >>> expect from standard FP? (short of unlimited precision ones) >> With respect to π and the zeros of sin() and cos()? Not really. I'll back off o

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Timothy Hochberg
On 2/21/07, Christopher Barker <[EMAIL PROTECTED]> wrote: Anne Archibald wrote: > Or, to see more clearly, try taking (on a pocket calculator, say) > sin(3.14) (or even sin(pi)). This is an interesting point. I took a class from William Kahan once (pass/fail, thank god!), and one question he po

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread David Goldsmith
I grew up a TI guy - my recollection is that they stated in the user manual that though the display could show "only" 10 decimal digits, memory saved and computations used 16; perhaps nowadays it is even more, but unless you're doing millions of sequential calculations (how often do you do that

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Christopher Barker
Robert Kern wrote: > Christopher Barker wrote: >> I wonder if there are any C math libs that do a better job than you'd >> expect from standard FP? (short of unlimited precision ones) > > With respect to π and the zeros of sin() and cos()? Not really. If > numpy.sin(numpy.pi) were to give you 0.0

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread David Goldsmith
Robert Kern wrote: > Christopher Barker wrote: > >> I wonder if there are any C math libs that do a better job than you'd >> expect from standard FP? (short of unlimited precision ones) >> > > With respect to π and the zeros of sin() and cos()? Not really. If > numpy.sin(numpy.pi) were to

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Robert Kern
Christopher Barker wrote: > I wonder if there are any C math libs that do a better job than you'd > expect from standard FP? (short of unlimited precision ones) With respect to π and the zeros of sin() and cos()? Not really. If numpy.sin(numpy.pi) were to give you 0.0, it would be *wrong*. numpy.

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Christopher Barker
Anne Archibald wrote: > Or, to see more clearly, try taking (on a pocket calculator, say) > sin(3.14) (or even sin(pi)). This is an interesting point. I took a class from William Kahan once (pass/fail, thank god!), and one question he posed to us was: How many digits of pi is used in an HP calcu

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread David Goldsmith
Anne Archibald wrote: > On 21/02/07, Zachary Pincus <[EMAIL PROTECTED]> wrote: > > >> A corrolary: in general do not two floating-point values for equality >> -- use something like numpy.allclose. (Exception -- equality is >> expected if the exact sequence of operations to generate two numbers >

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread David Goldsmith
As far as a computer is concerned, those numbers are "around" zero - "growing-up" w/ Matlab, e.g., one quickly learns to recognize these numbers for what they are. One way to return zero for numbers like these is if numpy.allclose(x, 0): return 0 (or 0*x to assure that 0 is the same type as x

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Zachary Pincus
It's true -- blindly using allclose isn't a lot better than blindly using equality testing. (Though given the choice between blindly using one and blindly using the other, I'd still probably vote for allclose... it won't get you quantum mechanics, but it'll do fine for a lot of other things

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread WolfgangZillig
Anne Archibald schrieb: > On 21/02/07, WolfgangZillig <[EMAIL PROTECTED]> wrote: >> Hi, >> >> 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: >> 1.22460635382e-016

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Anne Archibald
On 21/02/07, Zachary Pincus <[EMAIL PROTECTED]> wrote: > A corrolary: in general do not two floating-point values for equality > -- use something like numpy.allclose. (Exception -- equality is > expected if the exact sequence of operations to generate two numbers > were identical.) I really can't

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Anne Archibald
On 21/02/07, WolfgangZillig <[EMAIL PROTECTED]> wrote: > Hi, > > 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: > 1.22460635382e-016 > 6.12303176911e-017 > > I've expecte

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Zachary Pincus
Your results are indeed around zero. >>> numpy.allclose(0, 1.22460635382e-016) True It's not exactly zero because floating point math is in general not exact. You'll need to check out a reference about doing floating point operations numerically for more details, but in general you should

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Robert Kern
WolfgangZillig wrote: > Hi, > > 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: > 1.22460635382e-016 > 6.12303176911e-017 > > I've expected something around 0. Can an

Re: [Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread Charles R Harris
On 2/21/07, WolfgangZillig <[EMAIL PROTECTED]> wrote: Hi, 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: 1.22460635382e-016 6.12303176911e-017 I've expected something around 0. C

[Numpy-discussion] what goes wrong with cos(), sin()

2007-02-21 Thread WolfgangZillig
Hi, 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: 1.22460635382e-016 6.12303176911e-017 I've expected something around 0. Can anybody explain what I am doing wrong here?