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-boun...@scipy.org [numpy-discussion-boun...@scipy.org] 
On Behalf Of Pauli Virtanen [p...@iki.fi]
Sent: 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 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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to