Remainder or modulo: why -7 mod 3 has two answers
The modulo operation gives what is left after a whole-number division. 17 divided by 5 is 3 with 2 left over, so 17 mod 5 is 2. The four numbers are always tied together by one rule: the dividend equals the divisor times the quotient, plus the remainder. Here, 17 = 5 × 3 + 2. Modulo is behind clock time, days of the week, checksums, hashing and every "every nth item" rule in a program.
With positive numbers, there is only one sensible answer. With a negative number, there are two. Take -7 divided by 3. The exact answer is -2.33. Round the quotient toward zero and you get -2, so the remainder is -7 minus 3 × -2, which is -1. Round the quotient down and you get -3, so the remainder is -7 minus 3 × -3, which is 2. Both satisfy the rule. They just pick a different quotient.
Programming languages split along that line. C, C++, Java, C#, JavaScript, Go, Rust and Swift round toward zero, so their % operator gives -1, and the result has the sign of the dividend. Python, Ruby, and the MOD function in Excel and Google Sheets round down, so they give 2, and the result has the sign of the divisor. A third convention, Euclidean modulo, always gives a result of 0 or more, whatever the signs. Rust offers it as rem_euclid. Java has Math.floorMod for the Python behaviour.
The difference causes real bugs. Code that wraps an index backwards through a list with (i - 1) % length works in Python and fails in JavaScript, where it gives -1 at the start of the list. Code that tests whether a number is odd with n % 2 == 1 misses negative odd numbers in C and JavaScript, where -3 % 2 is -1. This calculator shows the three conventions side by side, so you can see which one your code is using and what the other would give.
Some limits are worth knowing. The calculator takes whole numbers only, with up to 10,000 digits each, and works them out exactly. It does not take decimals, so it does not reproduce the fractional remainders that JavaScript and Python give for numbers such as 5.5 % 2. The divisor cannot be 0. The language names describe each language's built-in % operator or MOD function; a library may define its own.