gh-153144: Avoid checking errno for atan2#153148
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
If this PR is merged, it looks to me like #146402 can (and should) be reverted. |
skirpichev
left a comment
There was a problem hiding this comment.
No, I doubt that this is a right approach. We must handle error in same way for all libm functions.
Perhaps, m_atan2() (like m_log1p() we have currently) could be restored (see #122681) to workaround broken platform functions.
The mathmodule currently has 3 ways of handling 1-argument libm functions:
Maybe it's not so bad to have |
|
Perhaps, we could modify math_2() helper to check that errno!=EDOM, if inputs and output are finite. When domain error occurs - result should be nan. But I think that a little wrapper for libm's atan2 is better, if we are going to add some workaround for the given issue. |
skirpichev
left a comment
There was a problem hiding this comment.
Please revert unrelated changes.
|
|
||
| For the majority of one-argument functions these rules are enough | ||
| to ensure that Python's functions behave as specified in 'Annex F' | ||
| to ensure that Python's functions behave as specified in Annex F |
| For most two-argument functions (copysign, fmod, hypot) these rules | ||
| are enough to ensure that Python's functions behave as specified in | ||
| Annex F of the C99 standard, with the 'invalid' and 'divide-by-zero' | ||
| floating-point exceptions mapping to Python's ValueError and the | ||
| 'overflow' floating-point exception mapping to OverflowError. |
There was a problem hiding this comment.
This too, except for the first line.
There was a problem hiding this comment.
Is better to leave the first line short or better to reflow the entire comment?
There was a problem hiding this comment.
Leave just change for the first line. Or even revert the whole change. (Technically, comment is still valid for atan2 too, assuming it conforms to Annex F. But not for hypot() ;-))
The C23 standard states that for
atan2andatan2pi:Since Python should not raise ValueError in either of these cases (i.e., when both arguments are zero or when the computation underflows), this PR avoids checking
errnowhen calling these trig functions. As a bonus,math.atan2()is about 4% faster.math.atan2(0.0, 0.0)andcmath.phase(0.0)using icx #153144The statement about range error in the standard should, I think, be interpreted as: