Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-28 Thread Mark Bakker
I'll file a ticket. Incidentally, if tanh(z) is simply programmed as (1.0 - exp(-2.0*z)) / (1.0 + exp(-2.0*z)) the problem is fixed. Thanks, Mark [clip] Not for large complex values: In [85]: tanh(1000+0j) Out[85]: (nan+nan*j) Yep, it's a bug. Care to file a ticket? The

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-28 Thread Pauli Virtanen
Fri, 28 Jan 2011 11:25:19 +0100, Mark Bakker wrote: I'll file a ticket. Incidentally, if tanh(z) is simply programmed as (1.0 - exp(-2.0*z)) / (1.0 + exp(-2.0*z)) This will overflow as z - -\infty. The solution is probably to use a different expression for Re(z) 0, and to check how other

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-28 Thread Mark Bakker
Good point, so we need a better solution that fixes all cases I'll file a ticket. Incidentally, if tanh(z) is simply programmed as (1.0 - exp(-2.0*z)) / (1.0 + exp(-2.0*z)) This will overflow as z - -\infty. The solution is probably to use a different expression for Re(z) 0, and to check

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-28 Thread Mark Bakker
Follow up: The behavior is correct for real argument: In [20]: sinh(1000) Out[20]: inf In [21]: cosh(1000) Out[21]: inf In [22]: tanh(1000) Out[22]: 1.0 So maybe we should look there for good logic, Mark On Fri, Jan 28, 2011 at 11:45 AM, Mark Bakker mark...@gmail.com wrote: Good point, so

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-28 Thread Pauli Virtanen
Fri, 28 Jan 2011 12:57:18 +0100, Mark Bakker wrote: Follow up: The behavior is correct for real argument: [clip] So maybe we should look there for good logic, In the real case you can do if (abs(z) cutoff) return sgn(z), which is not the right thing to do for complex numbers. Anyway,

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-28 Thread Nadav Horesh
From: numpy-discussion-boun...@scipy.org [numpy-discussion-boun...@scipy.org] On Behalf Of Mark Bakker [mark...@gmail.com] Sent: 28 January 2011 12:45 To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] Error in tanh for large complex argument Good point, so we need

[Numpy-discussion] Error in tanh for large complex argument

2011-01-27 Thread Mark Bakker
Hello list, When computing tanh for large complex argument I get unexpected nans: tanh works fine for large real values: In [84]: tanh(1000) Out[84]: 1.0 Not for large complex values: In [85]: tanh(1000+0j) Out[85]: (nan+nan*j) While the correct answer is: In [86]:

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-27 Thread Pauli Virtanen
Thu, 27 Jan 2011 11:40:00 +0100, Mark Bakker wrote: [clip] Not for large complex values: In [85]: tanh(1000+0j) Out[85]: (nan+nan*j) Yep, it's a bug. Care to file a ticket? The implementation is just sinh/cosh, which overflows. The fix is to provide an asymptotic expansion (sgn Re z),

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-27 Thread Nadav Horesh
: 27 January 2011 13:11 To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] Error in tanh for large complex argument Thu, 27 Jan 2011 11:40:00 +0100, Mark Bakker wrote: [clip] Not for large complex values: In [85]: tanh(1000+0j) Out[85]: (nan+nan*j) Yep, it's a bug. Care to file

Re: [Numpy-discussion] Error in tanh for large complex argument

2011-01-27 Thread David Cournapeau
On Thu, Jan 27, 2011 at 8:37 PM, Nadav Horesh nad...@visionsense.com wrote: The C code return the right result with glibc 2.12.2 (linux 64 + gcc 4.52). Same for me on mac os x (not sure which C library it is using, the freebsd one ?) for ppc, i386 and amd64, cheers, David