http://en.m.wikipedia.org/wiki/Modulo_operation
In many programming languages (C, Java) the modulo operator is defined so that the modulus has the same sign as the first operand. This means that the following equation holds:
(-a) % n = -(a % n)
For example, -8%3 would be -2, since 8%3 is 2.
Others, such as Python, compute a % n instead as the positive remainder when diving by n, which means
(-a) % n = n - (a % n)
For example, -8%3 is 1 because 3-(8%3) is 3-2 is 1.
Note that in modular arithmetic adding or subtracting any multiple of n does not change the result because "equality" (or congruence if you prefer that term) is defined with respect to divisibility: X is equal to 0 if it is a multiple of n, and A is equal to B if A-B is a multiple of n. For example -2 is equal to 1 modulo 3 because -2-1 = -3 is divisible by 3.