numexpr icon indicating copy to clipboard operation
numexpr copied to clipboard

Improve accuracy of expm1 for complex arguments

Open thangleiter opened this issue 2 years ago • 1 comments

Fixes #418.

thangleiter avatar Aug 19 '22 12:08 thangleiter

The imaginary part of the result differs slightly from the numpy result (hence the nulp=2500) in the test. Strangely, this difference disappears if the exponential of the real part is assigned to a temporary value (i.e., as it is currently computed):

static void
nc_expm1(npy_cdouble *x, npy_cdouble *r)
{
    double a = sin(x->imag / 2);
    double b = exp(x->real);
    r->real = expm1(x->real) * cos(x->imag) - 2 * a * a;
    r->imag = b * sin(x->imag);
    return;
}

Any idea why @robbmcleod?

thangleiter avatar Aug 19 '22 12:08 thangleiter

Closing as I implemented myself, thanks for the contribution though!

robbmcleod avatar Oct 26 '22 02:10 robbmcleod