summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-12-16 06:14:55 -0800
committerGitHub <noreply@github.com>2019-12-16 06:14:55 -0800
commit2b03ae6f7ab945daeb6f9ae265dbfbbbe0b68f0b (patch)
treeee33c0ceceb8fbb91390646e2b6658a146673a15 /numpy
parentbba2bd2012c6e1726e455c50995b685d12773c22 (diff)
parent253084777f4b9aeb517253dbe5059fb90bf57a96 (diff)
downloadnumpy-2b03ae6f7ab945daeb6f9ae265dbfbbbe0b68f0b.tar.gz
Merge pull request #15110 from tillahoffmann/expm1
MAINT: Fix expm1 instability for small complex numbers.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/umath/funcs.inc.src6
-rw-r--r--numpy/core/tests/test_umath.py6
2 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/umath/funcs.inc.src b/numpy/core/src/umath/funcs.inc.src
index 10ed66e50..9c59cc8fb 100644
--- a/numpy/core/src/umath/funcs.inc.src
+++ b/numpy/core/src/umath/funcs.inc.src
@@ -360,9 +360,9 @@ nc_exp2@c@(@ctype@ *x, @ctype@ *r)
static void
nc_expm1@c@(@ctype@ *x, @ctype@ *r)
{
- @ftype@ a = npy_exp@c@(x->real);
- r->real = a*npy_cos@c@(x->imag) - 1.0@c@;
- r->imag = a*npy_sin@c@(x->imag);
+ @ftype@ a = npy_sin@c@(x->imag / 2);
+ r->real = npy_expm1@c@(x->real) * npy_cos@c@(x->imag) - 2 * a * a;
+ r->imag = npy_exp@c@(x->real) * npy_sin@c@(x->imag);
return;
}
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index e892e81d2..ae1090c23 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -888,6 +888,12 @@ class TestExpm1(object):
assert_equal(ncu.expm1(np.inf), np.inf)
assert_equal(ncu.expm1(-np.inf), -1.)
+ def test_complex(self):
+ x = np.asarray(1e-12)
+ assert_allclose(x, ncu.expm1(x))
+ x = x.astype(np.complex128)
+ assert_allclose(x, ncu.expm1(x))
+
class TestHypot(object):
def test_simple(self):