Skip to main content

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

Results

How to compare remainders

  1. Enter integer a. The default -7 is chosen so the three remainder conventions split.
  2. Enter integer n. n cannot be 0. The default is 5.
  3. Read the Euclidean remainder, JavaScript a % n, the floored remainder, and the truncated quotient.
  4. 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 % nRemainder follows the sign of a
Flooreda - n * floor(a / n)
Default examplea = -7, n = 5. JS remainder -2. Euclidean 3.
Quotient showntrunc(a / n)
n = 0Rejected

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.

Modulo questions

What is -7 mod 5 in JavaScript?
a % n is -2. The remainder follows the sign of a.
What is the Euclidean remainder for -7 and 5?
3. That row stays non-negative when n is positive.
Can n be 0?
No. The page rejects a zero modulus.
Is this the same as GCD?
No. GCD folds a list with the Euclidean algorithm. This page is one remainder pair.
Does floored remainder always match Euclidean?
They match for the default positive n. A negative n can split the rows. Read both.
Are a and n uploaded?
No. The remainders run in this tab.