How to correctly hardcode GDScript float constants?

Godot Version

4.3.stable

Question

In my script I use the constants 1/6. I do not want to waste time constantly recomputing it by writing it as a float/float division.

1.0 / 6.0

Is it faster to write it out in decimal to a certain number of digits? To my understanding, conversion will still occur.
If yes, how many digits should I write? Does it depend on the engine’s float precision?

Or can I write some binary representation as a float literal?

Or should it be computed first, and stored in a constant variable?

You can select the line that you want to compute and then right-click and choose “evaluate selection” this automatically calculates the value and should be the number the engine uses

1 Like