Use num_scientific (Grisu2) when stringifying JSON with full precision#108836
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Sep 30, 2025
Merged
Use num_scientific (Grisu2) when stringifying JSON with full precision#108836Repiteo merged 1 commit intogodotengine:masterfrom
num_scientific (Grisu2) when stringifying JSON with full precision#108836Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
|
JSON.parse_string also incorrectly parsing huge integers. For example 109775241382906655 becomes 109775241382906660. |
Member
Author
|
@DjSapsan No, it's not possible, because that is beyond what can be represented by |
f0a7154 to
a238af4
Compare
Contributor
|
Thanks! |
num_scientific (Grisu2) when stringifying JSON with full precision
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.
The JSON specification supports scientific notation for numbers. https://www.json.org/json-en.html
This PR changes the behavior of the JSON stringify function so that when the
p_full_precisionflag is true, it usesnum_scientific, and therefore the Grisu2 algorithm introduced in PR #98750.There has been a bug for awhile where glTF files exported from Godot are reported as invalid by the glTF validator because the accessor min and max values do not match the data in the accessor:
I've known about this bug for years, but it hasn't been a priority. I decided to solve it, and turns out, it's not a bug with the glTF exporter, it's a bug with Godot's JSON stringify function. This PR fixes that function, and also adjusts the glTF code to set
p_full_precisionto true. With this PR, the exported glTF file passes validation:Also: In most cases, this approach can be way more efficient.
1.7976931348623157e+308is much shorter than179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0