Repository navigation
Keep 16 fractional digits for xsd:decimal and fix large-value parsing - #83
Open
MathiasVDA wants to merge 2 commits into
Open
MathiasVDA wants to merge 2 commits into
MathiasVDA wants to merge 2 commits into
Conversation
XSD 1.1 Part 2 5.4 requires support for decimals with up to 16 fractional digits. With a scale of 12, values such as 760.3865996838672 were truncated when read. Refs DataTreehouse#70. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…decimals
rust_decimal's 96-bit mantissa cannot hold large values at the default scale,
and rescale() silently shifted the decimal point (9999999999999.5 became
999999999999.95). Parse the digits into the i128 mantissa directly and
reject values with more integer digits than the type allows.
STR() on a decimal cast the fixed-scale value to a string with padding zeros
("1.5000000000000000"). Trim it to the canonical form, as the N-Triples writer
does. Refs DataTreehouse#70.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Requested by Mathias
Part of #70 (the value side; the padded Turtle output reported there is not changed here).
Before:
xsd:decimalliterals with more than 12 fractional digits were truncated when read:760.3865996838672became760.386599683867, and0.0000000000001became0.rust_decimal's 96-bit mantissa cannot hold them at the default scale, andrescale()silently shifted the decimal point (9999999999999.5became999999999999.95). At scale 12 this starts at about 10^16.STR()on a decimal returned the fixed-scale string with padding zeros ("1.500000000000").After:
STR()returns the canonical form, trimmed like the N-Triples writer already does:"1.5","798","-12.34".How:
default_decimal_scale()goes from 12 to 16.parse_xsd_decimalparses the digits straight into thei128mantissa instead of going throughrust_decimal.str_functiontrims trailing zeros (and a trailing.) forxsd:decimal.Trade-off: the largest supported integer part shrinks from 26 to 22 digits. If you prefer to keep scale 12, the parser and
STR()changes still stand on their own.Tests:
py_maplib/tests/test_decimal_precision.py(round-trip of 13 and 16 fractional digits, large values, canonicalSTR()). The existing basics, JSON, HDT, read/write, RDF parser and custom-function tests pass.🤖 Generated with Claude Code