Modulo Calculator
The remainder under three conventions at once — the Euclidean answer as the headline, JavaScript’s % named as the remainder operator it is, and the conversion law that turns one into the other.
Modulo Calculator
Results recalculate instantly on every keystroke. Nothing you type is transmitted.
What this result does not account for
- Whole numbers only — decimal remainders are a different operation (fmod)
- One modulus per run; no modular exponentiation
In short: 17 mod 5 = 2 under every convention — on positives all three agree: 17 = 3×5 + 2. The conventions split on negatives: −7 mod 3 is 2 in mathematics and Python (the remainder stays in 0 … n−1) but −1 from JavaScript’s %, which carries the dividend’s sign. The conversion law ((a % n) + n) % n lands on 2 from either starting point.
Formula
a = q × n + r · 0 ≤ r < |n|
JS: r carries the sign of a · fix: ((a % n) + n) % n
the Euclidean remainder is the canonical representative of the congruence class.
Worked Example
- Divide and floor. the mathematical convention floors the quotient toward −∞: −7 ÷ 3 floors to −3, so r = −7 − (−3)×3 = 2.
- Name the language. JavaScript % truncates the quotient toward zero instead: −7 ÷ 3 truncates to −2, so r = −7 − (−2)×3 = −1. Same class, different representative.
- Convert. ((a % n) + n) % n works in every language: add the modulus once, and the remainder is home in 0 … n−1 — −1 + 3 = 2.
The clock is the honest example: 25 o’clock is 1 o’clock because 25 mod 12 = 1. Array wrap-around needs the conversion law — index −1 under JavaScript % stays −1, which is no index at all.
Strengths & Limits Of This Model
Where this engine is strong
- All three conventions printed side by side, each named for its language
- The conversion law is applied to YOUR numbers, not quoted in the abstract
Where it stops
- No modular arithmetic (no (a·b) mod n composition)
- No negative-modulus convention table
Practical Use Cases
Clock and calendar wraps
hours, weekdays, and every cycle that bites its own tail
Array wrap-around
negative indices only index if the remainder is forced non-negative
Parity and divisibility
n mod 2, and “divides evenly” as remainder 0
Methodology & Editorial Standards
Normalize the modulus to |n| (refusing 0). Euclidean/floored remainder r = ((a % n) + n) % n with q = (a − r)/n printed in the identity. Truncated remainder (the JS % value) printed beside it, and the conversion law shown applied to the actual inputs. Both operands must be whole numbers.
Computation runs in IEEE-754 double precision at full internal precision; rounding to two decimal places occurs strictly at the display layer, so no cumulative drift enters the result. All monetary outputs use accounting presentation — grouped thousands, two decimals, negatives in parentheses — so figures can be transcribed directly into a model or working paper. Division-by-zero and out-of-domain inputs return an em-dash rather than a misleading number.
This engine was reconciled against an independent reference implementation and hand-verified for the worked example above before release. Our full five-stage review process is published on the About Us page.
Disclaimer. This calculator is provided for informational and modelling purposes only and does not constitute financial, tax, legal, medical, or engineering advice. Verify all figures with a qualified professional before acting on them.
Modulo Calculator — 9 Expert FAQs
9 analyst-written answers to the questions practitioners actually ask — optimised for voice and answer-engine retrieval.
Why do JavaScript and Python disagree about −7 mod 3?
They round the QUOTIENT differently. JavaScript’s % truncates toward zero (−2.33 → −2), leaving a remainder with the dividend’s sign: −1. Python floors toward −∞ (−2.33 → −3), leaving a remainder with the divisor’s sign: 2. Both satisfy a = q×n + r; the difference of the two remainders is exactly one modulus. Same congruence class, different representative.
So is JavaScript’s % not really modulo?
Name it what the spec names it: the REMAINDER operator. For non-negative inputs it agrees with modulo everywhere; on negatives it keeps the dividend’s sign while the mathematical modulo keeps the result in 0 … n−1. Code that wraps around a cycle — playlist indexes, clock faces, ring buffers — must apply the conversion law or it will produce −1 where it needs 2.
What is the conversion law and why does it always work?
((a % n) + n) % n. The first % leaves r in −n+1 … n−1 (truncated convention); adding n lifts the negative half into 0 … n−1 without moving the positive half out (it just overshoots, and the outer % folds it back). Two lines, language-independent — the cheapest insurance in arithmetic code.
Which answer is THE right one?
For the mathematics, the Euclidean one — 0 ≤ r < n — which is why the headline card prints it. The truncated remainder is not wrong, it is a different representative of the same class: −1 and 2 are congruent mod 3 because they differ by exactly 3. The page prints both and the conversion between them, so no answer ever needs defending, only naming.
What breaks when the modulus is 0?
Everything — a mod 0 is undefined: there is no q with 0×q = a unless a is 0, and no remainder class exists. JavaScript returns a not-a-number, Python raises, C does whatever the hardware feels like. The page refuses the modulus of 0 outright and says why.
How does the clock example actually work?
25 o’clock is 1 o’clock because 25 = 2×12 + 1: the remainder after removing full turns is the hour hand’s honest position. The same law wraps weekdays (day 10 of a 7-day cycle is day 3) and playlist indices (track −2 of 12 is track 10 — but only after the conversion law, since raw % leaves −2).
Why does the page ask for a positive modulus?
Mathematical convention takes remainders with respect to a POSITIVE modulus — a negative divisor makes the “range” of the remainder ambiguous across languages. The page uses |n| so the remainder always has a home in 0 … |n|−1, and the identity a = q×n + r is printed with the n you actually gave.
Where does modulo show up outside clocks?
Everywhere cycles exist: hashing (bucket = key mod table size), parity (n mod 2), divisibility tests (n mod 9 and digit sums), shuffling and cycling through arrays, checksums, and the entire clock arithmetic behind RSA. The common thread: a quantity that only matters up to multiples of n.
What is the quotient q doing on the page?
The identity needs it: a = q×n + r. The page prints the identity with the Euclidean q and r so the division is visible — 17 = 3×5 + 2 — because a remainder without its quotient is half a story. With the floored q, r is always home in 0 … n−1; that is the convention the whole page is built on.