[Numpy-discussion] Error in tanh for large complex argument
Nadav Horesh
nadavh at visionsense.com
Thu Jan 27 06:37:33 EST 2011
The C code return the right result with glibc 2.12.2 (linux 64 + gcc 4.52). However I get the same nan+nan*j with python.
Nadav
________________________________________
From: numpy-discussion-bounces at scipy.org [numpy-discussion-bounces at scipy.org] On Behalf Of Pauli Virtanen [pav at iki.fi]
Sent: 27 January 2011 13:11
To: numpy-discussion at 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 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.
OTOH, the glibc-provided C99 function doesn't fare too well either:
#include <math.h>
#include <complex.h>
#include <stdio.h>
int main()
{
complex double z = 1000;
double x, y;
z = ctanh(z); x = creal(z); y = cimag(z);
printf("%g %g\n", x, y);
return 0;
}
### -> Prints 0 0 on glibc 2.12.1
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion at scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list