Actually, you ask 2 questions, the title is only the 1st. ;-) The answer to the first question is that `mod` translates to C's `%`, and the specification for `%` in C is that negative numbers gives negative results; that is, `-5 % 4 == 1` in C.
I can think of more than one answer to the second question. The simplest (?) is
probably to take the absolute value before computing the modulus:
var a = -5
var b = 4
echo a mod b # gives -1
echo abs(a) mod b # gives 1
Run
