Replies: 3 comments 1 reply
-
Why is this an improvement over just This is the way it works in both Java and C# btw, it's actually common in programming languages from what I can find, where have you seen different? |
Beta Was this translation helpful? Give feedback.
1 reply
-
I've just come across this because of a bug, only to find 7/3 = 2 !!! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A recurring question in Godot's Reddit channel is that why
1 / 2
(or something similar) returns0
. Integer division is not a common concept in all languages, especially in script languages. I guess GDScript has integer division only because of C++.My proposal is that the division operator
/
should always return a float, no matter what the operand types are (floats or integers).1 / 2
would return float0.5
.4 / 2
would return float2.0
.A new integer division operator should be added. It could be for example
//
.1 // 2
woud return0
,4 // 2
would return2
. Using integer division with any other operand types than two integers would be an error.Now using the integer division would always be a decision the programmer does knowingly, not by accident.
Beta Was this translation helpful? Give feedback.
All reactions