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

Vector wrong cast to string and normalized() function inconsistency on Linux #18590

Closed
samdze opened this issue May 3, 2018 · 3 comments
Closed
Labels

Comments

@samdze
Copy link
Contributor

samdze commented May 3, 2018

Godot version:
Godot v3.0.3.rc1.official.63e70e3

OS/device including version:
Windows 10 64 bit, macOS 10.12.6, Linux 4.15.17

Issue description:
The same instructions give different results in Linux compared to Windows and macOS.
The following:

var v1 = Vector2(0, 1)
var op1 = int(v1.x + v1.y)
var v2 = Vector2(0, 1).normalized()
var op2 = int(v2.x + v2.y)
print("%s: %s %s: %s"%[v1, op1, v2, op2])

outputs
(0, 1): 1 (0, 1): 1
on Windows and macOS,
and outputs
(0, 1): 1 (0, 1): 0
on Linux.

On Linux it seems that normalized() returns a Vector2 with a Y component slightly smaller than 1, which is then truncated by the cast to int. However, the Vector2 is casted to string as if the Y value were exactly 1.
The same inconsistency appears with Vector3 too.

@akien-mga
Copy link
Member

That's simply because components of Vector2 are float, so 1.0 might be 1.00000213 or 0.99999127 depending on hardware, software, luck... So it can be that instead of 0.0 + 1.0 you get -0.00000123 + 0.9999983, which is less than 1.0 and is therefore cast to 0. The call to normalize() just adds some more precision error since it basically does 1.0 / 1.0 and 0.0 / 1.0.

@groud
Copy link
Member

groud commented May 3, 2018

We really need to document that somewhere.
Closing as this is an expected behaviour, and has already been discussed like in #17449 or #17971.

@groud groud closed this as completed May 3, 2018
@groud groud added the archived label May 3, 2018
@samdze
Copy link
Contributor Author

samdze commented May 3, 2018

Yes, float numbers are often imprecise, but numbers like 0 and 1 have exact binary representations.
There aren't non-representable values involved.
Shouldn't the above operations between the exact representations of 1 and 0 result in exact representations?

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

No branches or pull requests

3 participants