Sumivo · Mathematics

Modulo Calculator

Find a mod n — the remainder of integer division — with the quotient and both remainder conventions, so negative dividends are unambiguous.

01 / inputs

integer
integer

02 / result

A MOD N

2

Result (Euclidean)
2
Truncated remainder
2
Quotient
3

Calculation trace

  1. 17 = 3 × 5 + 2
    2
    Division algorithm
  2. 17 mod 5 = 2
    2
    Euclidean modulo

Maintained by Jack Shi

§

How it works

Modulo is the remainder left after integer division. By the division algorithm, for a dividend a and a non-zero modulus n there is a unique quotient q and remainder r with a = q·n + r. This tool reports the Euclidean modulo, where the result is always kept in the range 0 ≤ r < |n|, and it also shows the truncated remainder returned by the % operator in C, Java and JavaScript, whose sign follows the dividend. The two agree when the dividend is non-negative and differ only when a negative dividend is not an exact multiple — for example −7 mod 3 is 2 in the Euclidean sense but −1 as a truncated remainder.

Assumptions & limits

  • Both inputs must be safe integers within ±9,007,199,254,740,991. BigInt arithmetic keeps the remainder and quotient exact; decimals and unsafe integers are rejected.
  • The modulus cannot be 0, because division by zero is undefined.
  • The main result uses the Euclidean convention (non-negative, 0 ≤ result < |modulus|); the truncated remainder is shown alongside it for programming contexts.
  • The quotient is the integer q that satisfies dividend = q × modulus + result exactly.

Verified runs

Synthetic examples executed at build revision be2e0e4 on . Cards round decimal results to 6 significant figures; matching uses full precision and the tolerance below. Matches cover the displayed fields, not every possible input or clinical or engineering validation.

  • Inputs: Dividend: 17 integer; Divisor: 5 integer

    Result: Result: 2 Euclidean remainder; Remainder: 2 truncated remainder (expected Result: 2 Euclidean remainder; Remainder: 2 truncated remainder) ✓

  • Inputs: Dividend: 0 integer; Divisor: 5 integer

    Result: Result: 0 Euclidean remainder; Remainder: 0 truncated remainder (expected Result: 0 Euclidean remainder; Remainder: 0 truncated remainder) ✓

  • Inputs: Dividend: 7 integer; Divisor: -3 integer

    Result: Result: 1 Euclidean remainder; Remainder: 1 truncated remainder (expected Result: 1 Euclidean remainder; Remainder: 1 truncated remainder) ✓

  • Inputs: Dividend: -7 integer; Divisor: 3 integer

    Result: Result: 2 Euclidean remainder; Remainder: -1 truncated remainder (expected Result: 2 Euclidean remainder; Remainder: -1 truncated remainder) ✓

How these runs were checked

Method: modulo@1.0.0. Expectations come from the listed test fixtures or hand arithmetic; they are not copied from these executions. Omitted optional inputs use the method defaults. Run dates record execution, not expert review or fresh measurements.

Download all verified runs (JSON) — full inputs, returned values, expectations, timestamps and buildRevision.

  • normal: . Absolute tolerance: 1e-10. Text and booleans match exactly. Full-precision result: Result: 2 Euclidean remainder; Remainder: 2 truncated remainder. Expected: Result: 2 Euclidean remainder; Remainder: 2 truncated remainder. Expectation: packages/calculator-core/tests/modulo.test.ts
  • boundary: . Absolute tolerance: 1e-10. Text and booleans match exactly. Full-precision result: Result: 0 Euclidean remainder; Remainder: 0 truncated remainder. Expected: Result: 0 Euclidean remainder; Remainder: 0 truncated remainder. Expectation: packages/calculator-core/tests/modulo.test.ts
  • sensitivity: . Absolute tolerance: 1e-10. Text and booleans match exactly. Full-precision result: Result: 1 Euclidean remainder; Remainder: 1 truncated remainder. Expected: Result: 1 Euclidean remainder; Remainder: 1 truncated remainder. Expectation: packages/calculator-core/tests/modulo.test.ts
  • signed: . Absolute tolerance: 1e-10. Text and booleans match exactly. Full-precision result: Result: 2 Euclidean remainder; Remainder: -1 truncated remainder. Expected: Result: 2 Euclidean remainder; Remainder: -1 truncated remainder. Expectation: packages/calculator-core/tests/modulo.test.ts

Reproduce from the source checkout with pnpm --filter @sumivo/web gen:verified-runs. A rebuild changes execution times; the revision identifies its Git starting point, including any uncommitted changes made for that build.

§

FAQ

What does modulo mean?
The modulo (or “mod”) is the remainder after dividing one integer by another. For 17 mod 5 the quotient is 3 and the remainder is 2, so 17 mod 5 = 2.
Why does this tool show two different remainders for negative numbers?
There are two common conventions. The Euclidean modulo always returns a non-negative result (0 ≤ r < |n|), so −7 mod 3 = 2. The truncated remainder used by the % operator in C, Java and JavaScript keeps the sign of the dividend, so −7 % 3 = −1. Both describe the same division; they just place the remainder differently. Python’s % and spreadsheet MOD follow the sign of the divisor: they agree with this nonnegative Euclidean result for positive divisors, but Python 7 % -3 is -2, whereas this tool returns 1.
Can the modulus be zero?
No. Dividing by zero is undefined, so a modulus of 0 is rejected.
What is modulo used for?
Wrapping values into a fixed range (clock arithmetic, array indices), checking divisibility (a is divisible by n when a mod n = 0), generating cyclic patterns, hashing, and checksum digits all rely on the modulo operation.
§

Related calculators

§

SOURCES