0 votes

Hi community :)

With respect to the IEEE Standard for Floating-Point Arithmetic (also known as IEEE 754) there are several types of floating-point numbers like float (32 bit) and double (64 bit) where float is single precision and double is double precision.
The standard mentions that float is able to represent ~7.2 decimal digits and double is able to represent ~15.9 decimal digits. And that is where I'm a little confused about how Godot represents floating-point numbers.

In GDScript I try to compute 1.0/3.0 and print the result with 16 decimal digits to check the amount of significant digits of floating-point numbers in Godot. This is the code of interest:

var result = 1.0/3.0
print("%.16f" % result)

The output of the above code is: 0.3333333333330000

If I try the same computation in Java or C++ I always get:

0.33333334 (in case of float)
0.3333333333333333 (in case of double)

So why does Godot represent floating-point numbers with 12 significant digits? This is not what I would expect with respect to IEEE 754.
Can anyone explain the above result? Or is the print() function the problem?

Here is some data to my OS and the used Godot version:
OS: Windows 8.1, 64 Bit
Godot version: 3.0.2 stable

Thank you :)

asked Mar 6, 2018 in Engine by Foxcataria (21 points)
edited Mar 6, 2018 by Foxcataria

This could be a bug or a mistake on the engine side, you should probably open an issue on GitHub.

Update:

At the moment it seems to be an issue with the print() function. The value of 1.0/3.0is stored correctly internally as a double precision floating-point number with the correct amount of significant digits stated by the IEEE 754 standard.

Here is the link to the issue I opened on GitHub:
https://github.com/godotengine/godot/issues/17312

The issue has been resolved. Now %f supports up to 16 decimal places.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.