gh-155526: correct errno handling in complex_abs() - #155527
Conversation
|
CC @vstinner |
|
This breaks >>> import cmath
>>> cmath.polar(complex(1e300, 1e-320))
Traceback (most recent call last):
...
OverflowError: math range error
|
|
@serhiy-storchaka, are you suggesting (1) reversion of |
Co-authored-by: hpkfft.com <paul@hpkfft.com>
Co-authored-by: hpkfft.com <paul@hpkfft.com>
|
I applied the 2 @hpkfft's suggestions (fixing typos). |
It fixes
Looks to be a very minor issue. Though, I can revert all C-API changes for a separate PR. |
Oh no, there is no need to revert C API changes in this PR. |
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the updated PR. Errno is now tested by all C _Py_c_abs() tests. There is also a test on Python abs() setting/checking errno. The changes are now well documented in Changelog entries and in the documentation. Good!
|
Merged, thanks for the fix, and sorry for being picky on documenting the change :-D @skirpichev: So what do you think of backporting the fix to Python 3.15 and older without changing _Py_c_abs() API? |
|
For the backport, I suppose that we can do simply what the issue title says: "complex_abs() should call _Py_c_abs() with errno=0 set": just set errno to 0 before calling _Py_c_abs(). |
…55527) abs(complex) no longer raises OverflowError if errno was set to ERANGE by some library call but abs() doesn't overflow. (cherry picked from commit e5d4fa2) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: hpkfft.com <paul@hpkfft.com>
|
GH-157341 is a backport of this pull request to the 3.15 branch. |
Should I create backports for <3.15 by hand? |
abs(complex) no longer raises OverflowError if errno was set to ERANGE by some library call but abs() doesn't overflow. _Py_c_abs() no longer sets errno to zero on success, but rather leaves it unchanged. Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: hpkfft.com <paul@hpkfft.com>
Uh oh!
There was an error while loading. Please reload this page.