Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bba873e

Browse files
authored
bpo-38992: avoid fsum test failure from constant-folding (GH-17513)
* Issue 38992: avoid fsum test failure * Add NEWS entry
1 parent ab513a3 commit bba873e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/test/test_math.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ def msum(iterable):
676676
float.fromhex('0x1.df11f45f4e61ap+2')),
677677
([(-1.)**n/n for n in range(1, 1001)],
678678
float.fromhex('-0x1.62a2af1bd3624p-1')),
679-
([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0),
680679
([1e16, 1., 1e-16], 10000000000000002.0),
681680
([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
682681
# exercise code for resizing partials array
@@ -685,6 +684,13 @@ def msum(iterable):
685684
float.fromhex('0x1.5555555555555p+970')),
686685
]
687686

687+
# Telescoping sum, with exact differences (due to Sterbenz)
688+
terms = [1.7**i for i in range(1001)]
689+
test_values.append((
690+
[terms[i+1] - terms[i] for i in range(1000)] + [-terms[1000]],
691+
-terms[0]
692+
))
693+
688694
for i, (vals, expected) in enumerate(test_values):
689695
try:
690696
actual = math.fsum(vals)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a test for :func:`math.fsum` that was failing due to constant folding.

0 commit comments

Comments
 (0)