Prevent XLS precision loss for large integers#637
Open
ViceSaber wants to merge 1 commit into
Open
Conversation
XLS stores numbers as 64-bit floats with 53-bit mantissa, so integers above 2^53-1 lose precision. Convert such integers to text strings to preserve exact values. Fixes jazzband#197
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #637 +/- ##
==========================================
- Coverage 93.14% 93.12% -0.03%
==========================================
Files 29 29
Lines 3226 3229 +3
==========================================
+ Hits 3005 3007 +2
- Misses 221 222 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Thanks for the PR, please add tests. I've just merged a fix for the lint teyit failure, please also rebase/merge |
Contributor
|
Another approach would have been to document that the XLS format is not adequate to store large integers. Is that format not on a disappearing trend? |
Member
|
I'm fine with either approach. This fix seems simple enough, but I expect XLS use is very low, and outputting XLS even lower. A docs change is safer, and we've not exactly had a huge number of requests for this. |
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.
Summary
Problem
XLS (Excel 97-2003) stores numeric values as 64-bit IEEE 754 floats with a 53-bit mantissa. Integers larger than 9,007,199,254,740,991 (2^53 - 1) lose precision when stored as numbers. For example,
568883383628111872becomes568883383628112000.Fix
In
dset_sheet, detect integers that exceed the float precision limit and convert them to strings before writing. Small integers continue to be stored as numbers for normal behavior.Testing
Verified that:
568883383628111872) are stored as text (cell type 1) and read back with full precision42) continue to be stored as numbers (cell type 2)Fixes #197