Skip to content

gh-153144: Avoid checking errno for atan2#153148

Open
hpkfft wants to merge 1 commit into
python:mainfrom
hpkfft:atan2
Open

gh-153144: Avoid checking errno for atan2#153148
hpkfft wants to merge 1 commit into
python:mainfrom
hpkfft:atan2

Conversation

@hpkfft

@hpkfft hpkfft commented Jul 5, 2026

Copy link
Copy Markdown

The C23 standard states that for atan2 and atan2pi:

A domain error may occur if both arguments are zero.
A range error occurs if x is positive and nonzero y/x is too close to zero.

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 errno when calling these trig functions. As a bonus, math.atan2() is about 4% faster.


The statement about range error in the standard should, I think, be interpreted as:

A range error occurs if (x is positive) and (y/x is nonzero) and (y/x is too close to zero).

@bedevere-app

bedevere-app Bot commented Jul 5, 2026

Copy link
Copy Markdown

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 skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant