Repository navigation
gh-153144: Avoid checking errno for atan2
#153148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hpkfft
wants to merge
21
commits into
python:main
Choose a base branch
from
hpkfft:atan2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
503fd4a
gh-153144: Avoid checking `errno` for `atan2`
hpkfft c9c51ad
gh-153144: Added NEWS entry
hpkfft 287e6ee
gh-153144: Modify comments as requested in review
hpkfft cbe759a
Merge branch 'main' into atan2
hpkfft 91257f2
Merge branch 'main' into atan2
hpkfft 25ec8e2
Add comments as requested in review
hpkfft 43f7398
Revert gh-146402 and update NEWS entry
hpkfft 5b6d005
Merge branch 'main' into atan2
skirpichev ead2720
Make NEWS entry a little shorter.
hpkfft d546e81
The copysign function does not need to check errno.
hpkfft f4ed052
Merge branch 'main' into atan2
hpkfft 82448e1
Add cmath tests and update NEWS entry
hpkfft 288fb8b
Merge branch 'main' into atan2
hpkfft be0ed87
Expand comments to explain why we ignore errno
hpkfft b991892
Merge branch 'main' into atan2
hpkfft 72842e1
Merge branch 'main' into atan2
hpkfft 11c56c4
Merge branch 'main' into atan2
hpkfft 6a92490
Change as requested in review
hpkfft 6a48f02
Merge branch 'main' into atan2
hpkfft 8594452
Add tests for math.atan2() and update NEWS
hpkfft 527afd1
Remove decorative `*` from comment in cmathmodule
hpkfft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -916,7 +916,7 @@ is_error(double x, int raise_edom) | |
| C89 but for which HUGE_VAL is not an infinity. | ||
|
|
||
| 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 | ||
|
hpkfft marked this conversation as resolved.
Outdated
|
||
| 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. | ||
|
|
@@ -1011,12 +1011,11 @@ math_1a(PyObject *arg, double (*func) (double), const char *err_msg) | |
| The last rule is used to catch overflow on platforms which follow | ||
| C89 but for which HUGE_VAL is not an infinity. | ||
|
|
||
| For most two-argument functions (copysign, fmod, hypot, atan2) | ||
| 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. | ||
| 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. | ||
|
hpkfft marked this conversation as resolved.
Outdated
|
||
| */ | ||
|
|
||
| static PyObject * | ||
|
|
@@ -1054,6 +1053,28 @@ math_2(PyObject *const *args, Py_ssize_t nargs, | |
| return PyFloat_FromDouble(r); | ||
| } | ||
|
|
||
| /* variant of math_2, to be used when the function being wrapped is known NOT | ||
| to need error checking (i.e., no overflow, invalid, or divide-by-zero). */ | ||
|
Comment on lines
+1064
to
+1065
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest expand this with atan2() example and remove other comments below. |
||
|
|
||
| static PyObject * | ||
| math_2ne(PyObject *const *args, Py_ssize_t nargs, | ||
| double (*func) (double, double), const char *funcname) | ||
| { | ||
| double x, y, r; | ||
| if (!_PyArg_CheckPositional(funcname, nargs, 2, 2)) | ||
| return NULL; | ||
|
picnixz marked this conversation as resolved.
|
||
| x = PyFloat_AsDouble(args[0]); | ||
| if (x == -1.0 && PyErr_Occurred()) { | ||
| return NULL; | ||
| } | ||
| y = PyFloat_AsDouble(args[1]); | ||
| if (y == -1.0 && PyErr_Occurred()) { | ||
| return NULL; | ||
| } | ||
| r = (*func)(x, y); | ||
|
hpkfft marked this conversation as resolved.
Outdated
|
||
| return PyFloat_FromDouble(r); | ||
| } | ||
|
|
||
| #define FUNC1(funcname, func, can_overflow, docstring) \ | ||
| static PyObject * math_##funcname(PyObject *self, PyObject *args) { \ | ||
| return math_1(args, func, can_overflow, NULL); \ | ||
|
|
@@ -1084,6 +1105,12 @@ math_2(PyObject *const *args, Py_ssize_t nargs, | |
| }\ | ||
| PyDoc_STRVAR(math_##funcname##_doc, docstring); | ||
|
|
||
| #define FUNC2NE(funcname, func, docstring) \ | ||
| static PyObject * math_##funcname(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { \ | ||
| return math_2ne(args, nargs, func, #funcname); \ | ||
| }\ | ||
| PyDoc_STRVAR(math_##funcname##_doc, docstring); | ||
|
|
||
| FUNC1D(acos, acos, 0, | ||
| "acos($module, x, /)\n--\n\n" | ||
| "Return the arc cosine (measured in radians) of x.\n\n" | ||
|
|
@@ -1115,11 +1142,11 @@ FUNC1(atan, atan, 0, | |
| "atan($module, x, /)\n--\n\n" | ||
| "Return the arc tangent (measured in radians) of x.\n\n" | ||
| "The result is between -pi/2 and pi/2.") | ||
| FUNC2(atan2, atan2, | ||
| FUNC2NE(atan2, atan2, | ||
|
hpkfft marked this conversation as resolved.
|
||
| "atan2($module, y, x, /)\n--\n\n" | ||
| "Return the arc tangent (measured in radians) of y/x.\n\n" | ||
| "Unlike atan(y/x), the signs of both x and y are considered.") | ||
| FUNC2(atan2pi, m_atan2pi, | ||
| FUNC2NE(atan2pi, m_atan2pi, | ||
| "atan2pi($module, y, x, /)\n--\n\n" | ||
| "Return the arc tangent (measured in half-turns) of y/x.\n\n" | ||
| "Unlike atanpi(y/x), the signs of both x and y are considered.") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.