-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConfigFile saving floats with low precision and unable to handle floats > 1e+06 #82424
Comments
Added the label "good first issue", but note to anyone solving this issue, there is some nuance here. Plain Variant floats are 64-bit C++ |
I’d love to take this issue.
I guess I can make a similar function like Or there is a |
As a workaround, I encode the float as a string using extends Node2D
func _ready():
var cfg = ConfigFile.new()
cfg.set_value("section", "key", String.num(1000001.0))
cfg.parse(cfg.encode_to_text())
assert(float(cfg.get_value("section", "key")) == 1000001.0) # Passes
|
Can I work on this issue? |
Of course. @jsjtxietian already has a pull request #82440 which needs more work. You can either work on this PR, or start from scratch. |
You should communicate with the author of that PR, see if they need any help, otherwise you're better off looking at some other issue |
@aniketmdinde Feel free to investigate and put more discussion here! |
Godot version
v4.2.dev.custom_build [2048fe5]
System information
Godot v4.2.dev (2048fe5) - Gentoo 2.14 - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 6600 (RADV NAVI23) () - AMD Ryzen 5 5600 6-Core Processor (12 Threads)
Issue description
There is an issue with the way
ConfigFile
encodes floating-point values. The low encoding precision is limited to the 6 biggest numbers, and since Godot's floating-point number is 32 bits, itsConfigFile
encoding should fail at a minimum of 1e+14.Examples
123456.0 gets encoded as "123456.0," and parsed to 123456.0, but the number 1234567.0 will be encoded as "1.23457e+06," and parsed to 1234570.0, which is wrong.
11111111111111.0, gets encoded as "1.11111e+13," and parsed to 11111100000000.0.
Proposed Fix
I suggest to only encode floats greater than 1e+14 in scientific notation, and to keep 14 digits of precision when doing so, while omitting trailing 0's. Otherwise, standard notation should be used.
Note
This is potentially a good issue to receive the label "good first issue."
Steps to reproduce
Minimal reproduction project
godot.zip
The text was updated successfully, but these errors were encountered: