-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-94906: Support multiple steps in math.nextafter #103881
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
Changes from all commits
77fb4ae
5e97978
0f2b30f
b90e86c
accc22f
8e1db39
6873347
1fff8b4
311f266
cd70fea
e0421b6
a8c83a7
88c46c4
2232bb4
a2724f6
b7b5ac6
b45f9c2
1f9d890
2153302
61c7c6e
04af22b
6527b77
66ef3f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import functools | ||
import unittest | ||
from math import isnan, nextafter | ||
from test.support import requires_IEEE_754 | ||
from test.support.hypothesis_helper import hypothesis | ||
|
||
floats = hypothesis.strategies.floats | ||
integers = hypothesis.strategies.integers | ||
|
||
|
||
def assert_equal_float(x, y): | ||
assert isnan(x) and isnan(y) or x == y | ||
|
||
|
||
def via_reduce(x, y, steps): | ||
return functools.reduce(nextafter, [y] * steps, x) | ||
|
||
|
||
class NextafterTests(unittest.TestCase): | ||
@requires_IEEE_754 | ||
@hypothesis.given( | ||
x=floats(), | ||
y=floats(), | ||
steps=integers(min_value=0, max_value=2**16)) | ||
def test_count(self, x, y, steps): | ||
assert_equal_float(via_reduce(x, y, steps), | ||
nextafter(x, y, steps=steps)) | ||
|
||
@requires_IEEE_754 | ||
@hypothesis.given( | ||
x=floats(), | ||
y=floats(), | ||
a=integers(min_value=0), | ||
b=integers(min_value=0)) | ||
def test_addition_commutes(self, x, y, a, b): | ||
first = nextafter(x, y, steps=a) | ||
second = nextafter(first, y, steps=b) | ||
combined = nextafter(x, y, steps=a+b) | ||
hypothesis.note(f"{first} -> {second} == {combined}") | ||
|
||
assert_equal_float(second, combined) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support multiple steps in :func:`math.nextafter`. Patch by Shantanu Jain and Matthias Gorgens. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.