Math
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 returns the remainder after dividing one number by another. For a mod n, divide a by n and keep what is left over. Example: 17 mod 5 = 2, because 17 = 3 x 5 + 2. The calculator shows both the quotient and the remainder so you can verify the full identity.
Why do truncated and floored mod give different results?
They only differ when a and n have opposite signs. Truncated mod (used by JavaScript, C, Java, Go) makes the remainder carry the sign of the dividend a. Floored mod (used by Python, Ruby, and most math texts) makes the remainder carry the sign of the divisor n. For positive inputs both methods produce the same result.
How does mod work with negative numbers?
Take -7 mod 3 as an example. Truncated gives -1, because -7 = (-2) x 3 + (-1). Floored gives 2, because -7 = (-3) x 3 + 2. Both satisfy the identity a = q x n + r. They just pick a different quotient q, which shifts the remainder accordingly.
What is clock arithmetic?
A standard clock face is modulo 12. If the time is 10:00 and you add 5 hours, the result is (10 + 5) mod 12 = 3:00. Modulo wraps a running count back into a fixed range, which is why it appears in clocks, calendars, weekday calculations, and cryptographic algorithms.
Which mod convention does my programming language use?
JavaScript, C, C++, Java, Go, Rust, and Swift use truncated mod, where the % operator follows the sign of the dividend. Python, Ruby, and Haskell use floored mod. The difference only matters for negative inputs, so always check which convention your language applies before relying on remainder behavior in production code.