]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38992: avoid fsum test failure from constant-folding (GH-17513) (GH-17530)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 9 Dec 2019 17:32:34 +0000 (09:32 -0800)
committerMark Dickinson <mdickinson@enthought.com>
Mon, 9 Dec 2019 17:32:34 +0000 (11:32 -0600)
* Issue 38992: avoid fsum test failure

* Add NEWS entry
(cherry picked from commit bba873e633f0f1e88ea12fb935cbd58faa77f976)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Lib/test/test_math.py
Misc/NEWS.d/next/Tests/2019-12-08-15-11-06.bpo-38992.cVoHOZ.rst [new file with mode: 0644]

index 6edc3e1a547a4907ce91e5add4708f88b747fdc6..ac978247fc917f7c5ce73d51d6626b3b1f0e50f7 100644 (file)
@@ -654,7 +654,6 @@ class MathTests(unittest.TestCase):
              float.fromhex('0x1.df11f45f4e61ap+2')),
             ([(-1.)**n/n for n in range(1, 1001)],
              float.fromhex('-0x1.62a2af1bd3624p-1')),
-            ([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0),
             ([1e16, 1., 1e-16], 10000000000000002.0),
             ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
             # exercise code for resizing partials array
@@ -663,6 +662,13 @@ class MathTests(unittest.TestCase):
              float.fromhex('0x1.5555555555555p+970')),
             ]
 
+        # Telescoping sum, with exact differences (due to Sterbenz)
+        terms = [1.7**i for i in range(1001)]
+        test_values.append((
+            [terms[i+1] - terms[i] for i in range(1000)] + [-terms[1000]],
+            -terms[0]
+        ))
+
         for i, (vals, expected) in enumerate(test_values):
             try:
                 actual = math.fsum(vals)
diff --git a/Misc/NEWS.d/next/Tests/2019-12-08-15-11-06.bpo-38992.cVoHOZ.rst b/Misc/NEWS.d/next/Tests/2019-12-08-15-11-06.bpo-38992.cVoHOZ.rst
new file mode 100644 (file)
index 0000000..815ae0f
--- /dev/null
@@ -0,0 +1 @@
+Fix a test for :func:`math.fsum` that was failing due to constant folding.