Re: [Numpy-discussion] Error in tanh for large complex argument
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 implementation is just sinh/cosh, which overflows. The fix is to provide an asymptotic expansion (sgn Re z), although around the imaginary axis the switch is perhaps somewhat messy to handle.
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 libraries do this in case the above still misses something. Pauli
participants (2)
-
Mark Bakker
-
Pauli Virtanen