Replies: 4 comments 3 replies
-
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.
-
I've just come across this because of a bug, only to find 7/3 = 2 !!! |
Beta Was this translation helpful? Give feedback.
-
This has been marked as closed but I don't see any resolution. Godot and GDScript in general are both very good but this issue is the worst aspect of it. Having integer division as the default is causing so many errors in my code, even though I'm aware of this stupid practice. Can someone explain how it makes any sense to have integer division as the default, why would anyone want (by default) 50/100=0 or 1/3 = 0. Who thought this was a good idea in the first place and how is it still like this? |
Beta Was this translation helpful? Give feedback.
-
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