Commit d20dd69d authored by Robert Bradshaw's avatar Robert Bradshaw

Fix complex powers of negative real values.

Fixes GH issue #1538.
parent 320d3c44
...@@ -264,9 +264,13 @@ static {{type}} __Pyx_PyComplex_As_{{type_name}}(PyObject* o) { ...@@ -264,9 +264,13 @@ static {{type}} __Pyx_PyComplex_As_{{type_name}}(PyObject* o) {
if (a.imag == 0) { if (a.imag == 0) {
if (a.real == 0) { if (a.real == 0) {
return a; return a;
} else if (a.real > 0) {
r = a.real;
theta = 0;
} else {
r = -a.real;
theta = atan2{{m}}(0, -1);
} }
r = a.real;
theta = 0;
} else { } else {
r = __Pyx_c_abs{{func_suffix}}(a); r = __Pyx_c_abs{{func_suffix}}(a);
theta = atan2{{m}}(a.imag, a.real); theta = atan2{{m}}(a.imag, a.real);
......
...@@ -48,6 +48,8 @@ def test_pow(double complex z, double complex w, tol=None): ...@@ -48,6 +48,8 @@ def test_pow(double complex z, double complex w, tol=None):
True True
>>> test_pow(complex(0.5, -.25), complex(3, 4), 1e-15) >>> test_pow(complex(0.5, -.25), complex(3, 4), 1e-15)
True True
>>> test_pow(-0.5, 1j, tol=1e-15)
True
""" """
if tol is None: if tol is None:
return z**w return z**w
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment