Remainder vs modulo for negative numbers
Why the % operator and a floored modulo disagree on negatives, how truncated and floored division cause it, and which to reach for in code.
Two answers to one question
For positive numbers the words remainder and modulo mean the same thing, so 17 divided by 5 leaves 2 either way. The disagreement starts with negatives. The remainder keeps the sign of the dividend, so -7 and 3 give -1, while the floored modulo keeps the sign of the divisor, giving 2. Both are correct under their own definition, which is exactly why this tool shows them side by side.
Truncated versus floored division
The split traces back to how the quotient is rounded. Truncated division rounds toward zero, so -7 divided by 3 becomes -2, and the remainder that makes the arithmetic balance is -1. Floored division rounds down toward negative infinity, so the same division becomes -3, and the matching modulo is 2. Each remainder is whatever is left after you multiply the rounded quotient by the divisor and subtract, so the rounding choice fixes the sign.
Why languages disagree
There is no single right convention, so language designers chose differently. C, Java, Go, Rust and JavaScript adopted the truncated remainder, meaning their % can return a negative value. Python, Ruby and the mathematical convention favor the floored modulo, which follows the divisor. Spreadsheet MOD functions usually follow the floored rule too. Porting a formula between these worlds without checking the sign rule is a classic source of off by one bugs.
Choosing the right one in practice
Reach for the floored modulo when you need a value that wraps cleanly, such as indexing into an array, cycling through days of the week, or placing something on a clock face, because it stays inside 0 to n minus 1 for a positive n. Reach for the raw remainder when you specifically want the sign of the dividend preserved, for example to tell how far past a boundary a negative measurement fell. When a language gives you only the remainder, the expression ((a % n) + n) % n converts it to the floored form.