In more detail
17 mod 5 = 2. It is used for clocks (15 mod 12 = 3), wrapping array positions and checking whether a number is even (n mod 2 = 0). For negative numbers, languages disagree: −7 mod 3 is 2 in Python but −1 in JavaScript and C.
Modulo gives the remainder after division: `a mod n` is what is left when a is divided by n.
Last reviewed:
17 mod 5 = 2. It is used for clocks (15 mod 12 = 3), wrapping array positions and checking whether a number is even (n mod 2 = 0). For negative numbers, languages disagree: −7 mod 3 is 2 in Python but −1 in JavaScript and C.