Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39288: Add math.nextafter(x, y) #17937
Conversation
Return the next floating-point value after x towards y.
This comment has been minimized.
This comment has been minimized.
I'm not sure about the unit tests: not sure if they are portable on any IEEE 754 implementation, and if the test would work on non-IEEE 754 implementation. Maybe the test should be decorated ith |
This comment has been minimized.
This comment has been minimized.
Yes, I think so. There's nothing to guarantee that the existing test would work on a non IEEE 754 system, should Python ever encounter one. Please could we also have tests covering all the various corner cases: signed zeros, infinities, nans, subnormals, etc.? There's a lot that can go wrong, and I don't think it's safe to trust that the platform's libm does the right thing. (We've tried that before.) |
@@ -2033,6 +2033,12 @@ def testComb(self): | |||
self.assertIs(type(comb(IntSubclass(5), IntSubclass(k))), int) | |||
self.assertIs(type(comb(MyIndexable(5), MyIndexable(k))), int) | |||
|
|||
def test_nextafter(self): | |||
self.assertEqual(math.nextafter(9223372036854775807.0, 0.0), |
This comment has been minimized.
This comment has been minimized.
mdickinson
Jan 10, 2020
Member
It would be clearer to use a value that's exactly representable here: 9223372036854775808.0
rather than 9223372036854775807.0
. Otherwise there are two effects going on: first, the literal is being rounded to a different value, and then that value is having nextafter
applied to it.
This comment has been minimized.
This comment has been minimized.
Oh, and once we have more comprehensive tests, it might be worth trying out the new "test on the buildbots" functionality with this PR, to ferret out any platforms that have dodgy implementations of nextafter. |
vstinner commentedJan 10, 2020
•
edited by bedevere-bot
Return the next floating-point value after x towards y.
https://bugs.python.org/issue39288