gh-119771: Set errno on overflows in _Py_c_pow() (#120256) · python/cpython@8a284e1 · GitHub
Skip to content

Commit 8a284e1

Browse files
authored
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().
1 parent 81480e6 commit 8a284e1

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

Doc/c-api/complex.rst

Lines changed: 2 additions & 0 deletions

Lib/test/test_capi/test_complex.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ def test_py_c_pow(self):
226226

227227
self.assertEqual(_py_c_pow(0j, -1)[1], errno.EDOM)
228228
self.assertEqual(_py_c_pow(0j, 1j)[1], errno.EDOM)
229-
self.assertEqual(_py_c_pow(*[DBL_MAX+1j]*2)[0], complex(*[INF]*2))
229+
max_num = DBL_MAX+1j
230+
self.assertEqual(_py_c_pow(max_num, max_num),
231+
(complex(INF, INF), errno.ERANGE))
232+
self.assertEqual(_py_c_pow(max_num, 2),
233+
(complex(INF, INF), errno.ERANGE))
230234

231235

232236
def test_py_c_abs(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Set :data:`errno` in :c:func:`_Py_c_pow` on overflows. Patch by Sergey B
2+
Kirpichev.

Objects/complexobject.c

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)