You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_Py_c_pow() should adjust errno on error conditions #119771
Right now we do this after invocation of the function or it's optimized alternative (for small integers). That has advantage as - IIUC - both algorithms may trigger error condition. On another hand, behaviour of the public C API function _Py_c_pow() (used in the CPython codebase only for complex_pow()) will differ from the pure-python pow()...
Other similar functions (complex_div() and complex_abs()) leave setting errno to corresponding C-API function.
My proposal: move _Py_ADJUST_ERANGE2() call to _Py_c_pow() and c_powi(). If that does make sense I'll provide a patch.
Well, do you suggest to wipe out c_powi()?:) That could solve also #117999, but performance impact is measurable:
$ python3.12 -m timeit -s 'a, b =1+1j, 10' 'pow(a, b)'
1000000 loops, best of 5: 230 nsec per loop
$ python3.12 -m timeit -s 'a, b =1+1j, 10.000001' 'pow(a, b)'
500000 loops, best of 5: 560 nsec per loop
Activity
vstinner commentedon Jun 3, 2024
It makes sense to me. You can add tests to
Lib/test/test_capi/test_complex.py.skirpichev commentedon Jun 3, 2024
I'm working on this. Things are worse than I expect: algorithm for small integer exponents produces
(nan+nanj), where_Py_c_pow()- overflows.a patch
vstinner commentedon Jun 3, 2024
Usually for numbers in Python, in case of doubt, correctness matters more than performance.
skirpichev commentedon Jun 3, 2024
Well, do you suggest to wipe out
c_powi()?:) That could solve also #117999, but performance impact is measurable:vstinner commentedon Jun 3, 2024
You can catch the overflow using something like that:
skirpichev commentedon Jun 3, 2024
Hmm, shouldn't errno set
_Py_c_prod()in this case?skirpichev commentedon Jun 4, 2024
See #120010
pythongh-119771: adjust errno on overflows in _Py_c_pow()
skirpichev commentedon Jun 8, 2024
PR is ready for review: #120256
gh-119771: Set errno on overflows in _Py_c_pow() (#120256)
vstinner commentedon Sep 18, 2024
Implemented by the change 8a284e1.
pythongh-119771: Set errno on overflows in _Py_c_pow() (python#120256)