Java Tip: modulo with negative numbers

Came across this issue of running a modulo command on a negative number when working on an extension. Java does not handle it correctly.

11 % 7 = 4 >> correct

-11 % 7 = -4 >> wrong

instead use:

Math.floorMod(-11,7) = 3 >> correct

ref

2 Likes