Skip to content

Commit

Permalink
bpo-38992: avoid fsum test failure from constant-folding (pythonGH-17513
Browse files Browse the repository at this point in the history
)

* Issue 38992: avoid fsum test failure

* Add NEWS entry
  • Loading branch information
mdickinson authored Dec 9, 2019
1 parent ab513a3 commit bba873e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ def msum(iterable):
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
Expand All @@ -685,6 +684,13 @@ def msum(iterable):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a test for :func:`math.fsum` that was failing due to constant folding.

0 comments on commit bba873e

Please sign in to comment.