Modulo Calculator
Type integers a and n. The page shows a Euclidean remainder (non-negative when n is positive), the JavaScript remainder a % n that follows the sign of a, and a floored remainder. n cannot be 0.
Rated 4.7 out of 5 based on 294 reviews
How to compare remainders
- Enter integer a. The default -7 is chosen so the three remainder conventions split.
- Enter integer n. n cannot be 0. The default is 5.
- Read the Euclidean remainder, JavaScript a % n, the floored remainder, and the truncated quotient.
- Use GCD when you need a greatest common divisor of several integers, not a remainder pair.
Integer remainder conventions
Euclidean, JavaScript truncated, and floored remainder
| Euclidean | ((a % n) + |n|) % |n|, non-negative when n > 0 |
|---|---|
| JavaScript a % n | Remainder follows the sign of a |
| Floored | a - n * floor(a / n) |
| Default example | a = -7, n = 5. JS remainder -2. Euclidean 3. |
| Quotient shown | trunc(a / n) |
| n = 0 | Rejected |
What modulo means on this page
Languages disagree on the sign of a remainder when a is negative. JavaScript a % n follows the dividend a, so -7 % 5 is -2. Many number-theory texts want a remainder in 0 .. n-1 when n is positive, which is 3 for that pair. Floored division uses floor(a/n) and can match the Euclidean remainder when n is positive. This page prints all three so you can match the convention you were assigned.
How the three remainders are computed
a and n must be integers. Euclidean remainder is ((a % n) + abs(n)) % abs(n). JavaScript remainder is the language operator. Floored remainder is a - n * floor(a / n). Truncated quotient is trunc(a / n). Greatest common divisor of a list is the GCD page, which uses the Euclidean algorithm on integers, not these remainder labels.
Euclidean remainder, JS remainder, and GCD
Knuth and many CAS tools prefer a non-negative remainder for positive n. IEEE remainder and C99 truncating division are still other conventions. Python // is floored, so Python % on positives matches the floored row here. Do not paste these results into a clock face unless you also wrap 24 yourself.
Use cases
A programming homework that asks why -7 % 5 is -2 in JavaScript. A number-theory check that wants 3. A quick look at truncating versus flooring quotients. Not a modular inverse solver.
Limits
Integers only. n cannot be 0. No modular inverse. No BigInt beyond what Number already holds. CZNull does not receive the numbers.