-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Vector floating point values are not matching what was assigned to it. #17971
Comments
its because float numbers does no support precise direct comparsion by nature, you should use something like this
|
Thanks I did not realize this. Perhaps GDScript should do this automatically. |
Floating point (in fractional part) have "exact" values for human eyes, on program level they always contains inaccuracy(its their nature) and due its inaccuracy they cannot be correctly compared on equality(just it). But dont panic, this inaccuracy is invisible for human eyes, did you see seams in Minecraft ? |
@K9Kraken Numbers like |
Thanks for the response, I was getting confused because I thought "vector.x = float" was the same as "float = float". Previous software I've used stored values in their vectors as floats so the numbers stayed the same when you assigned them. Also thinking about this I don't think it is related to the issues I linked to above. |
Leaving this open as it's not yet clear if there is an bug here (in addition to the expected precision issues of float). From IRC:
|
Vector3 use single precision floats, Variant (default variable type) uses double precision, both can't represent Single is |
|
Unfortunately there is no way to have perfectly-precise representations of all decimal numbers in binary floating point formats. However, the solution as @Chaosus mentioned is to use approximate-equality comparison methods. I have a pull request open here #18992 which does several things to improve approximate equality methods, including changing the Vector, Color, etc, comparison methods to use approximate equality comparisons, and exposing these to GDScript. |
Closing as per above comment. |
Godot version:
Godot 3.0.2
OS/device including version:
Manjaro Linux 17.1.7
Issue description:
When creating a Vector or assigning numbers to it that have floating point values results in the vector holding a number that is not equal to the original number.
The number in the vector should be the same number that was assigned to it. This has been causing me a few issues and road blocks in my development.
It is possibly the cause or related to these issues:
#17820
#17307
Also when trying to compare a number with floating point values to a vector's value it will return false even if they are the same exact number.
Steps to reproduce:
******* I tested this in Godot 2.1.4 and the issue is similar *******
In Godot 2.1.4 a float suffers from this bug where in Godot 3.0.2 the float works correctly but the Vectors are still suffering from this bug.
The text was updated successfully, but these errors were encountered: