godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Vector3 note and observations

Open CristianoSimao opened this issue 2 years ago • 5 comments

Your Godot version: 3.4.3 Issue description: Lack of explanation URL to the documentation page: Please read the link bellow. https://github.com/godotengine/godot-docs/pull/5853/commits/07025fc8a3160b7705a5021351ce641eb828f5cd

I put the text in the wrong place, please if anyone can read my opinion and put my text in the right place I would be grateful.

CristianoSimao avatar Jun 01 '22 16:06 CristianoSimao

I think a good idea would be for us to write a document explaining floating point in more detail and then link to it from the many places it would be helpful (e.g. shader docs, classes that have floating point comparison, floating point data classes)

clayjohn avatar Jun 01 '22 22:06 clayjohn

Ok, this is good, but I writed the explanation about Vector3 because the bug has been confirmed here: https://github.com/godotengine/godot/issues/43476 And for beginners like me the documentation passes the feeling that all will work ok, but in reality you can't even store a simple value like 3.56 because the internal code in Godot mess the values and store something like 3.5699998 Little errors in floating points after math operations is OK, but Godot causes error in a simple stored value operation. Because this I think some explanation should be presented in the documentation, or solve the bug. This type of error is very important because all operations in 3D work on top of Vector3.

CristianoSimao avatar Jun 02 '22 00:06 CristianoSimao

And a tip about the "scale of World" will help to understand you can not trust on numbers inside Vector3.

CristianoSimao avatar Jun 02 '22 00:06 CristianoSimao

If you store a value like 3.45 in a Vector3 position, the real value stored can be 3.458978.
a simple value like 3.56 because the internal code in Godot mess the values and store something like 3.5699998

This is misleading, the values are much closer than this. https://www.h-schmidt.net/FloatConverter/IEEE754.html

3.45 is stored as 3.4500000476837158203125 with 32-bit floats. 3.56 is stored as 3.559999942779541015625 with 32-bit floats.

or solve the bug.

It's not a bug that can be solved, unless you want to just increase the amount of bits to 64 (or on exotic hardware, 128), or switched to a fixed point system (I don't recommend it), or switch to a decimal system (bad idea).

And a tip about the "scale of World" will help to understand you can not trust on numbers inside Vector3.

With Godot 4.0, you'll be able to use 64-bit floats inside of a Vector3 if you compile Godot with float=64. For 3.45, instead of 3.45000004768, you can store it as 3.4500000000000001776, which has a lot more precision.

I'm not sure where we should document this, but I 100% agree that we should document all this somewhere. Perhaps an article focused on large world support that includes information like 64-bit floats and level streaming and maybe origin shifting.

aaronfranke avatar Jun 16 '22 16:06 aaronfranke

Perhaps an article focused on large world support that includes information like 64-bit floats and level streaming and maybe origin shifting.

This sounds like a good manual page to write :slightly_smiling_face:

It should also document how to compile a build with double precision support (and why it requires a separate build in the first place).

Calinou avatar Jun 16 '22 16:06 Calinou