Modulo operation on negative numbers
-
An example:
-1%3 returns -1, not 2.Is it supposed to be like this?
-
not sure how that's even possible!
-
@MikeDX I made my own as a workaround. I think this is correct (please tell me if I'm wrong):
function mod(a, n) return a - floor(a/n) * n
-
This is definitely a bug. I'm going to test it here and file an issue on our side if i can reproduce it.
Thanks for the report and the workaround!
-
@MikeDX I think it cannot be said as a bug.
In general, the sign of the result of a modulo operator depends on a programming language.Typical results are listed here:
https://en.wikipedia.org/wiki/Modulo_operation -
@Minatsu That article is a bit above my level of comprehension, but it seems the difference between languages is normally only the sign of the result. In this case the absolute value of the result is different than what I would have expected. I'm not very familiar with other languages, but are there others that works like this?
-
having spoken to Luke about this, we believe -1%3 should be -1. This fits in with the modulo operator linked in the wiki page above.
Behind the scenes, Fuze uses the c modulo operator.