Remainder(modulus) operator returning negative values when it shouldn't

I was having problems when using the remainder function until I realized that the function returns negative values when it shouldn’t

-1 % 4
this should equal to 3 but makecode interprets this as -1.

because of this values are constrained incorrectly and equations that would work in any actual computer language don’t work in makecode

is this bug known and how long until it can be fixed?

This is the correct behavior; JavaScript, along with the c like languages (c / c++ / java / etc) all share the same behavior with %, treating it as a remainder instead of a true modulus operator.

If I recall correctly, python does have % as modulus not remainder, which I’ll probably have to file a bug on as I’m assuming we don’t handle that in our python implementation (confirmed and filed here)

1 Like