Skip to content

Commit 46e18aa

Browse files
eendebakptclaude
andcommitted
gh-NNNN: Add regression test for long-mantissa halfway-plus-epsilon
Covers the failure shape of a shortest-then-round strtod that truncates its mantissa buffer without carrying a "non-zero tail was dropped" flag through to the tie-break: the truncated form looks exactly like a halfway case and rounds-to-even the wrong way. The test constructs the midpoint between 1.0 and the next double (1.0 + 2**-52), pads with 800 zeros, and appends a '1'. The value is strictly above the halfway by 10**-857, so any bignum-capable strtod must round UP — fast_float's Eisel-Lemire + digit-comparison fallback handles this correctly, making the test pass as-is. The test is placed alongside test_strtod.StrtodTests.test_particular so it's part of the suite that already runs against every strtod patch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 925e587 commit 46e18aa

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/test/test_strtod.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,24 @@ def test_particular(self):
429429
for s in test_strings:
430430
self.check_strtod(s)
431431

432+
def test_halfway_plus_epsilon_long_mantissa(self):
433+
"""Regression test for long-mantissa halfway-plus-epsilon cases.
434+
435+
The construction is "(exact midpoint between 1.0 and the next
436+
double)" + 800 zeros + "1". The value sits strictly *above* the
437+
halfway by 10**-857, so bignum-backed strtod must round UP to
438+
1.0 + 2**-52 rather than ties-to-even DOWN to 1.0.
439+
440+
This is the exact shape that breaks a shortest-then-round
441+
strtod that truncates its mantissa buffer without carrying a
442+
"non-zero was dropped" flag through to the tie-break — the
443+
truncated form looks like an exact halfway and rounds the
444+
wrong way. fast_float's Eisel-Lemire + digit-comparison
445+
bignum fallback handles this correctly.
446+
"""
447+
halfway = "1.00000000000000011102230246251565404236316680908203125"
448+
s = halfway + "0" * 800 + "1"
449+
self.assertEqual(float(s), 1.0 + 2 ** -52)
450+
432451
if __name__ == "__main__":
433452
unittest.main()

0 commit comments

Comments
 (0)