Commit ba006541 authored by Robert Bradshaw's avatar Robert Bradshaw

Pure real results for pure real complex powers.

parent d20dd69d
......@@ -264,6 +264,10 @@ static {{type}} __Pyx_PyComplex_As_{{type_name}}(PyObject* o) {
if (a.imag == 0) {
if (a.real == 0) {
return a;
} else if (b.imag == 0) {
z.real = pow{{m}}(a.real, b.real);
z.imag = 0;
return z;
} else if (a.real > 0) {
r = a.real;
theta = 0;
......
......@@ -64,6 +64,8 @@ def test_int_pow(double complex z, int n, tol=None):
[True, True, True, True, True, True, True, True, True]
>>> [test_int_pow(complex(2, 0.5), k, 1e-14) for k in range(0, 10)]
[True, True, True, True, True, True, True, True, True, True]
>>> test_int_pow(-0.5, 5, tol=1e-15)
True
"""
if tol is None:
return z**n + <object>0 # add zero to normalize zero sign
......
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