summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorMatthias Görgens <matthias.goergens@gmail.com>2023-05-19 20:03:49 (GMT)
committerGitHub <noreply@github.com>2023-05-19 20:03:49 (GMT)
commit6e39fa19555043588910d10f1fe677cf6b04d77e (patch)
tree04f9df16fd8871323c195e79f2afc251c2882410 /Lib/test/test_math.py
parentc3f43bfb4bec39ff8f2c36d861a3c3a243bcb3af (diff)
downloadcpython-6e39fa19555043588910d10f1fe677cf6b04d77e.zip
cpython-6e39fa19555043588910d10f1fe677cf6b04d77e.tar.gz
cpython-6e39fa19555043588910d10f1fe677cf6b04d77e.tar.bz2
gh-94906: Support multiple steps in math.nextafter (#103881)
This PR updates `math.nextafter` to add a new `steps` argument. The behaviour is as though `math.nextafter` had been called `steps` times in succession. --------- Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index f282434..2bda610 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -2296,11 +2296,20 @@ class MathTests(unittest.TestCase):
float.fromhex('0x1.fffffffffffffp-1'))
self.assertEqual(math.nextafter(1.0, INF),
float.fromhex('0x1.0000000000001p+0'))
+ self.assertEqual(math.nextafter(1.0, -INF, steps=1),
+ float.fromhex('0x1.fffffffffffffp-1'))
+ self.assertEqual(math.nextafter(1.0, INF, steps=1),
+ float.fromhex('0x1.0000000000001p+0'))
+ self.assertEqual(math.nextafter(1.0, -INF, steps=3),
+ float.fromhex('0x1.ffffffffffffdp-1'))
+ self.assertEqual(math.nextafter(1.0, INF, steps=3),
+ float.fromhex('0x1.0000000000003p+0'))
# x == y: y is returned
- self.assertEqual(math.nextafter(2.0, 2.0), 2.0)
- self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0)
- self.assertEqualSign(math.nextafter(+0.0, -0.0), -0.0)
+ for steps in range(1, 5):
+ self.assertEqual(math.nextafter(2.0, 2.0, steps=steps), 2.0)
+ self.assertEqualSign(math.nextafter(-0.0, +0.0, steps=steps), +0.0)
+ self.assertEqualSign(math.nextafter(+0.0, -0.0, steps=steps), -0.0)
# around 0.0
smallest_subnormal = sys.float_info.min * sys.float_info.epsilon
@@ -2325,6 +2334,11 @@ class MathTests(unittest.TestCase):
self.assertIsNaN(math.nextafter(1.0, NAN))
self.assertIsNaN(math.nextafter(NAN, NAN))
+ self.assertEqual(1.0, math.nextafter(1.0, INF, steps=0))
+ with self.assertRaises(ValueError):
+ math.nextafter(1.0, INF, steps=-1)
+
+
@requires_IEEE_754
def test_ulp(self):
self.assertEqual(math.ulp(1.0), sys.float_info.epsilon)