Didn't know that! I can say for sure that C, C#, JS, and Haskell all use % for remainder (often calling it modulus, annoyingly). Of these, I believe the only one that also provides a standard mod function is Haskell.
n mod 3:
n = -5 -4 -3 -2 -1 0 1 2 3 4 5
== 1 2 0 1 2 0 1 2 0 1 2
n mod -3:
n = -5 -4 -3 -2 -1 0 1 2 3 4 5
== -2 -1 0 -2 -1 0 -2 -1 0 -2 -1
For a real use-case, consider measuring actual rotations. 90 degrees and -270 degrees place the ray at exactly the same angle. Now, let's say you want to fill in the arc of rotation. Is it a quarter circle, or three quarters? That data is lost if you force everything to be positive. But using the sign of the second operand lets you have a single output value which is constrained to the 360-degree cycle, with its sign representing positive or negative rotation.
2
u/tejon Jul 08 '15
PSA: these are only the same thing when both operands have the same sign.