Replies: 3 comments 1 reply
-
In GDScript you can do this: |
Beta Was this translation helpful? Give feedback.
-
GDScript seems to be in good company here: C++, JavaScript, C#... Addendum: Wikipedia has a table on how the operator is implemented in multiple languages: https://en.wikipedia.org/wiki/Modulo#In_programming_languages Anyway, I found a proposal on the topic: #3736 |
Beta Was this translation helpful? Give feedback.
-
Thank you for the idea! Let's close this discussion for consolidation (there is already a proposal, as theraot said). Note that this breaks compatibility, so cannot be done in 4.x anyway. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
currently in gdscript, the modulo operator behaves strangely with negative operands. here's a table showing the results of some modulo operations in gdscript as well as python (where the operator has a different, and in my opinion better, implementation):
to show why the behavior in python is probably more useful, take the example of normalizing an angle into the range
0..360
. in python, this is easily achievable -- to normalize the anglea
you just calculatea % 360
. but in gdscript, you have to do something like this:(i suppose
(a % 360 + 360) % 360
is also an option, but that's still 3 unreadable operations compared to one readable one.)i can't think of any case where gdscript's behavior would be desired.
the cases where the divisor is negative are much less important than the case where the dividend is negative and the divisor is positive, but i personally think the results in python make a lot more intuitive sense.
of course, this is probably a useless suggestion because
Beta Was this translation helpful? Give feedback.
All reactions