Repository navigation
fix: float sums give the same digits on Python 3.11 and 3.12+ - #341
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #341 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 148 149 +1
Lines 17515 17588 +73
Branches 3550 3561 +11
=========================================
+ Hits 17515 17588 +73
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #334
Python 3.12 made the built-in
sumcompensated (Neumaier) for floats; 3.11 adds left to right, so the same inputs gave results that differ in the last digits. The package now sums throughflahax.float_sum:sum(same object), so nothing changes there.sum(calls in 39 modules ofsrc/flahaxuse it; a test fails if a baresum(is added again.This is option 3 on the issue, not
math.fsum:fsumwould change the digits on every version and slow the solver's hot loop.Evidence
recommend(three target sets), aqueous solves of the four PHREEQC fixtures and the delivery example: before, 3.11.17 differed from 3.12.11, 3.13.15 and 3.14.0; after, all four are identical, and the 3.12+ digests did not change.sumon 300,000 random cases (floats, ints, bools, inf, nan, -0.0, mixed, different starts): 0 mismatches on 3.12.11 and 3.13.15.tests/test_float_sum.pypins 23 vectors taken from the 3.13 built-in, on every Python.outputs/test-runs/2026-11-27-xver-fix/(local).Known limits
float_sumrepeats the integer handling of 3.12/3.13 for ints below 263; CPython itself uses the platformlongthere (32 bit on Windows), which only matters for ints above 231 added after a float.