summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSergey B Kirpichev <skirpichev@gmail.com>2024-09-18 08:39:11 (GMT)
committerGitHub <noreply@github.com>2024-09-18 08:39:11 (GMT)
commit8a284e189673582e262744618f293f9901a32e49 (patch)
treebacc735fda350b18f021cbd9e8c1b679529520c7 /Objects
parent81480e6edb34774d783d018d1f0e61ab5c3f0a9a (diff)
downloadcpython-8a284e189673582e262744618f293f9901a32e49.zip
cpython-8a284e189673582e262744618f293f9901a32e49.tar.gz
cpython-8a284e189673582e262744618f293f9901a32e49.tar.bz2
gh-119771: Set errno on overflows in _Py_c_pow() (#120256)
Before we did this in complex_pow() and behavior of the public C API function _Py_c_pow() was different from the pure-python pow().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 4a8dac6..787235c 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -173,6 +173,8 @@ _Py_c_pow(Py_complex a, Py_complex b)
}
r.real = len*cos(phase);
r.imag = len*sin(phase);
+
+ _Py_ADJUST_ERANGE2(r.real, r.imag);
}
return r;
}
@@ -567,12 +569,12 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z)
// 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);
+ _Py_ADJUST_ERANGE2(p.real, p.imag);
}
else {
p = _Py_c_pow(a, b);
}
- _Py_ADJUST_ERANGE2(p.real, p.imag);
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError,
"zero to a negative or complex power");