[Numpy-discussion] Error in tanh for large complex argument
pav at iki.fi
Thu Jan 27 06:11:54 EST 2011
Thu, 27 Jan 2011 11:40:00 +0100, Mark Bakker wrote:
> Not for large complex values:
> In : tanh(1000+0j)
> Out: (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:
complex double z = 1000;
double x, y;
z = ctanh(z); x = creal(z); y = cimag(z);
printf("%g %g\n", x, y);
### -> Prints 0 0 on glibc 2.12.1
More information about the NumPy-Discussion