fix: preserve exact binary64 digits in decimal formats - #1097
Merged
stephenamar-db merged 2 commits intoJul 30, 2026
Merged
Conversation
Motivation: High-precision %f and fixed-form %g formatting started from the shortest round-tripping decimal string, hiding meaningful trailing digits of the binary64 value. Modification: Use the exact binary64 decimal value when fixed formatting needs more than 15 digits, propagate the original %g significant precision, and use half-even rounding for the exact path. Add non-tie and exact-halfway regressions while preserving the public five-argument JVM descriptor. Result: High-precision fixed decimal output matches Python from the same IEEE-754 value, including ties-to-even, without changing the legacy low-precision rounding path or JVM binary compatibility. References: - databricks#1097 - https://jsonnet.org/ref/stdlib.html#std-format
He-Pin
force-pushed
the
fix/format-exact-binary64-precision
branch
from
July 29, 2026 08:27
44d9ecb to
c5677c3
Compare
Motivation: The original tests lacked coverage at the precision 15/16 threshold (where the code switches from legacy to exact path) and for extreme values like subnormals and the %g fixed-form path. Modification: Add assertions for: precision-15 boundary (pi), %.20f of 0.1 and 1e-10 (exact binary64 trailing digits), subnormal 5e-324 at %.16f, and %.20g exercising the useExactDecimal parameter propagation. Result: The precision threshold and edge cases are now regression-protected.
stephenamar-db
approved these changes
Jul 30, 2026
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.
Motivation
BigDecimal(number)uses the shortest round-trip decimal, not the exact binary64 value. When%for fixed-form%grequested >15 digits, sjsonnet padded the shortened decimal and hid meaningful trailing digits.Modification
BigDecimal.exact(number)for fixed formatting above 15 fractional digits.%g's significant precision so its fixed-form path can select exact conversion.%gregressions.Result
std.format("%.16f", 3.14159265358979323)3.14159265358979303.14159265358979313.14159265358979323.14159265358979323.1415926535897931std.format("%.17f", 0.1)0.100000000000000000.100000000000000010.100000000000000000.100000000000000020.10000000000000001std.format("%.17f", 3.14159265358979323)3.141592653589793003.141592653589793123.141592653589793283.141592653589793283.14159265358979312std.format("%.17g", 31.4159265358979323)31.4159265358979331.41592653589793131.41592653589793231.41592653589793231.415926535897931Half-even rounding verified against go-jsonnet, jrsonnet, and Python. Full matrix (JVM/JS/Wasm/Native) +
checkFormatpassed.High-precision scientific notation is handled separately in #1095.
References
std.format