-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
GDScript: Modulo operator does not function on floats #10004
Comments
Can't reproduce on latest master 3a3915b Edit: tried on Godot 3 alpha 1 Linux x86_64, no error. |
Can you screenshot/copy the compilation error? |
My apologies, turns out the issue in particular is that you can not use modulo on floats. In particular I get the error
|
We could make it call But as long as GDScript is dynamically typed, keeping it only available for |
So you can cast if computing with the integral part is what you really want or use That also makes your code more explicit and your intent more clear. |
it's not a bug, it's a feature (tm),intended to avoids mistakes. Use fmod() for floats. |
Note that JavaScript allows the % operator to be used on floats. |
I also think it's good to keep as a feature; people complain about duck typing precisely because of such things, so let's not make things more confusing needlessly. |
ok, will close this as discussion is exhausted and there is no consense |
I know this is a weird problem, but I made a workaround. x = x - y * floor(x / y) if you think about it, it works in all situations and functions the same way as modulo does. |
Well that's the definition of the modulo, so yeah, it works :) But it's simpler to just use the builtin |
I know this is a weird problem, but I made a workaround. x = x - y * floor(x / y) if you think about it, it works in all situations and functions the same way as modulo does. |
Operating system or device - Godot version:
Windows 10
Godot 3 alpha-1
Issue description:
Using the modulo operator in GDScript only works for integers. It should also work for floats.
Steps to reproduce:
Attempting to do the following math results in compilation errors, preventing your app from running
The text was updated successfully, but these errors were encountered: