Modulo Calculator
Compute a mod n with both truncated (JavaScript) and floored (Python) conventions. Handles negative numbers, decimals, and shows the full division equation.
Compute a mod n
Truncated and floored mod only differ when a and n have opposite signs.
Remainder (truncated)
-1
-7 = -2 * 3 + -1
Truncated remainder
-1
Floored remainder
2
Quotient (trunc)
-2
Frequently Asked Questions about the Modulo Calculator
What is the modulo operation?
Modulo gives the remainder after integer division. For a mod n, you divide a by n and keep what is left over. Example: 17 mod 5 = 2, because 17 = 3 * 5 + 2.
Why do truncated and floored mod give different results?
They only differ when a and n have opposite signs. Truncated mod (used by C, Java, JavaScript) lets the remainder follow the sign of the dividend a. Floored mod (used by Python, Ruby, mathematicians) lets it follow the sign of the divisor n.
How does mod work with negative numbers?
Take -7 mod 3. Truncated gives -1, because -7 = -2 * 3 + (-1). Floored gives 2, because -7 = -3 * 3 + 2. Both equations are valid, they just pick different quotients.
What is clock arithmetic?
A clock is mod 12. If it is 10 o'clock and you wait 5 hours, the time is (10 + 5) mod 12 = 3 o'clock. Modulo wraps numbers around a fixed range, which is why it shows up in clocks, calendars, and cryptography.
Which mod does my programming language use?
JavaScript, C, C++, Java, Go, Rust, and Swift use truncated mod (% follows the dividend). Python, Ruby, Haskell, and most math papers use floored mod. Always check before relying on remainder behavior with negative inputs.