For −7 mod 3, the result is 2, while a language that keeps the sign of a gives −1
Why your number may differ
Programming languages disagree on negative results. Python gives 2 for −7 % 3, but JavaScript and C give −1.
Frequently asked questions
What does mod mean?
a mod n is the remainder left after dividing a by n. For example 17 mod 5 = 2, because 17 = 3 × 5 + 2.
How are negative numbers handled?
The main result follows the mathematical convention, with a remainder from 0 up to n − 1 for a positive n. Many programming languages instead keep the sign of a, so that result is shown too.
Where is modulo used?
In clock arithmetic, checking whether a number is even or odd, check digits and cycling through lists.