Apply rtos_fix hack for handling 32-bit floats on all calls to rtos_fix#110616
Merged
Conversation
Contributor
|
Tested and working as described. A huge QoL upgrade for those on |
Calinou
approved these changes
Sep 17, 2025
Member
Calinou
left a comment
There was a problem hiding this comment.
Tested locally, it works as expected. Code looks good to me.
When using Tools > Upgrade Project Files on the 3D platformer demo, this is the only change:
[node name="Circle" type="MeshInstance3D" parent="."]
-transform = Transform3D(1, 0, 0, 0, -3.61999e-06, -1, 0, 1, -3.61999e-06, 0.00550658, 0.532125, 0.000651598)
+transform = Transform3D(1, 0, 0, 0, -3.6199901e-06, -1, 0, 1, -3.6199901e-06, 0.00550658, 0.532125, 0.000651598)I've tried various other demos and changes are similarly minimal, so this change should be safe in terms of VCS diffs.
Contributor
|
Thanks! |
rtos_fix hack for handling 32-bit floats on all calls to rtos_fix
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.
This PR was made in response to this comment #98750 (comment)
I don't think there is any harm in always applying this hack to all float serialization. As a brief reminder, in all cases, this is strictly better than the behavior in Godot 4.4.
In Godot 4.4 and earlier, it would always serialize 6 digits of a float, which resulted in precision loss when serializing. In Godot 4.5, it uses Grisu2 instead to precisely serialize, however this can cause problems when Godot tells Grisu2 to serialize a double when the underlying data was a 32-bit float. I added a hack in PR #98750 that checks if it's equivalent to the 32-bit float value, and then serializes assuming the value is a 32-bit float, which seamlessly avoids issues for users, though it does mean that for double sources, 1 in 2^29 values will be off by 2^-23.
This PR changes this to apply to all floats, including Vector2, Vector3, Packed*Arrays, etc. In practice, this only changes behavior for Vector2, Vector3, etc for double-precision builds of Godot, and it has just one behavior change for single-precision builds of Godot, PackedFloat64Array. Test code:
In master, this is printed:
With this PR, this is printed: