-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-94906: Support multiple steps in math.nextafter #94908
Closed
Closed
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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 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
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2022-07-16-17-15-29.gh-issue-94906.C4G8DG.rst
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Support multiple steps in :func:`math.nextafter`. Patch by Shantanu Jain. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -3781,14 +3781,17 @@ math.nextafter | |
x: double | ||
y: double | ||
/ | ||
* | ||
steps: int = 1 | ||
|
||
Return the next floating-point value after x towards y. | ||
Return the floating-point value the given number of steps after x towards y. | ||
[clinic start generated code]*/ | ||
|
||
static PyObject * | ||
math_nextafter_impl(PyObject *module, double x, double y) | ||
/*[clinic end generated code: output=750c8266c1c540ce input=02b2d50cd1d9f9b6]*/ | ||
math_nextafter_impl(PyObject *module, double x, double y, int steps) | ||
/*[clinic end generated code: output=14190eb869199e5a input=a794e7a79768ee25]*/ | ||
{ | ||
int i; | ||
#if defined(_AIX) | ||
if (x == y) { | ||
/* On AIX 7.1, libm nextafter(-0.0, +0.0) returns -0.0. | ||
|
@@ -3802,7 +3805,14 @@ math_nextafter_impl(PyObject *module, double x, double y) | |
return PyFloat_FromDouble(y); | ||
} | ||
#endif | ||
return PyFloat_FromDouble(nextafter(x, y)); | ||
if (steps < 1) { | ||
PyErr_SetString(PyExc_ValueError, "steps must be >= 1"); | ||
return NULL; | ||
} | ||
for (i = 0; i < steps; i++) { | ||
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. You can support this without a loop. See this pure Python prototype for how that can work. |
||
x = nextafter(x, y); | ||
} | ||
return PyFloat_FromDouble(x); | ||
} | ||
|
||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can allow zero steps just fine.