Skip to content
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

Always print floats as float literals (ex: trailing decimal) #7894

Closed
aaronfranke opened this issue Sep 27, 2023 · 1 comment · Fixed by godotengine/godot#47502
Closed

Always print floats as float literals (ex: trailing decimal) #7894

aaronfranke opened this issue Sep 27, 2023 · 1 comment · Fixed by godotengine/godot#47502
Milestone

Comments

@aaronfranke
Copy link
Member

aaronfranke commented Sep 27, 2023

Describe the project you are working on

This isn't related to a specific project.

Describe the problem or limitation you are having in your project

print(0)
print(0.0)
print(Vector3(0.0, 1.0, 1.2))

Currently, when printing floats in GDScript, the trailing .0 is excluded. The above prints would print out 0, 0, and Vector3(0, 1, 1.2). This means that the values being printed do not necessarily match the type used in GDScript, and when debugging it's hard to tell if the value 0 is an int or a float because they are identical.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Change the behavior so that floats are always printed as valid float literals. So, the above example would print 0, 0.0, and Vector3(0.0, 1.0, 1.2).

This seems like a fairly straight-forward change, but it has a lot of nuance and wide-reaching implications for all areas of the engine, so it needs to be done with care and a lot of testing. A lot of places will need adjustment including the GDScript tests and the C# bindings generator. One of the points of nuance is that different types have different precision, which needs to be taken into account when printing.

This doesn't affect ABI compatibility, so it could be done in a 4.x release, but also it does significantly change behavior so it could be seen as a breaking change.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This is a mostly working attempt: godotengine/godot#47502

The feature was approved in a PR review meeting in June 2021, but the PR is still pending.

If this enhancement will not be used often, can it be worked around with a few lines of script?

This will be used extremely often. Every Godot dev ever will use this feature.

Is there a reason why this should be core and not an add-on in the asset library?

Printing floats is a core feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants