summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@google.com>2016-11-30 12:57:09 -0800
committerRobert Bradshaw <robertwb@google.com>2016-11-30 12:57:35 -0800
commitba0065411d516b2b36178eadf86957dfca289065 (patch)
tree9c88166ef71db386413c88de3882495eb5f5f911
parentd20dd69dd803026810b819e85e55effd1932feb1 (diff)
downloadcython-ba0065411d516b2b36178eadf86957dfca289065.tar.gz
Pure real results for pure real complex powers.
-rw-r--r--Cython/Utility/Complex.c4
-rw-r--r--tests/run/complex_numbers_T305.pyx2
2 files changed, 6 insertions, 0 deletions
diff --git a/Cython/Utility/Complex.c b/Cython/Utility/Complex.c
index 64a440f6e..2b75ed282 100644
--- a/Cython/Utility/Complex.c
+++ b/Cython/Utility/Complex.c
@@ -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;
diff --git a/tests/run/complex_numbers_T305.pyx b/tests/run/complex_numbers_T305.pyx
index cf5a5b30d..faf0bdb80 100644
--- a/tests/run/complex_numbers_T305.pyx
+++ b/tests/run/complex_numbers_T305.pyx
@@ -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