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

Mark Bakker markbak at gmail.com
Fri Jan 28 05:25:19 EST 2011


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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110128/5274f902/attachment.html>


More information about the NumPy-Discussion mailing list