Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44698: Restore complex pow behaviour for small integral exponents #27772

Merged
Prev Previous commit
Remove unnecessary local variable; restore comment
  • Loading branch information
mdickinson committed Aug 16, 2021
commit a74c34e10f5d29f33f7a2f38cc85b18901e5d32f
11 changes: 5 additions & 6 deletions Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ static PyObject *
complex_pow(PyObject *v, PyObject *w, PyObject *z)
{
Py_complex p;
Py_complex exponent;
Py_complex a, b;
TO_COMPLEX(v, a);
TO_COMPLEX(w, b);
Expand All @@ -517,13 +516,13 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z)
return NULL;
}
errno = 0;
exponent = b;
if (exponent.imag == 0.0 && exponent.real == floor(exponent.real)
&& fabs(exponent.real) <= 100.0) {
p = c_powi(a, (long)exponent.real);
// Check whether the exponent has a small integer value, and if so use
// a faster and more accurate algorithm.
if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= 100.0) {
p = c_powi(a, (long)b.real);
}
else {
p = _Py_c_pow(a, exponent);
p = _Py_c_pow(a, b);
}

Py_ADJUST_ERANGE2(p.real, p.imag);
Expand Down