Skip to content

Commit 99c7be1

Browse files
committed
run _Py_ADJUST_ERANGE2 only for finite input
1 parent 7f25e09 commit 99c7be1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Objects/complexobject.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ _Py_c_pow(Py_complex a, Py_complex b)
333333
r.real = len*cos(phase);
334334
r.imag = len*sin(phase);
335335

336-
_Py_ADJUST_ERANGE2(r.real, r.imag);
336+
if (isfinite(a.real) && isfinite(a.imag)
337+
&& isfinite(b.real) && isfinite(b.imag))
338+
{
339+
_Py_ADJUST_ERANGE2(r.real, r.imag);
340+
}
337341
}
338342
return r;
339343
}
@@ -753,9 +757,13 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z)
753757
errno = 0;
754758
// Check whether the exponent has a small integer value, and if so use
755759
// a faster and more accurate algorithm.
756-
if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= INT_EXP_CUTOFF) {
760+
if (b.imag == 0.0 && b.real == floor(b.real)
761+
&& fabs(b.real) <= INT_EXP_CUTOFF)
762+
{
757763
p = c_powi(a, (long)b.real);
758-
_Py_ADJUST_ERANGE2(p.real, p.imag);
764+
if (isfinite(a.real) && isfinite(a.imag)) {
765+
_Py_ADJUST_ERANGE2(p.real, p.imag);
766+
}
759767
}
760768
else {
761769
p = _Py_c_pow(a, b);

0 commit comments

Comments
 (0)