This calculator computes a mod n and shows the remainder under both common conventions plus the integer quotient. It is for programmers and students who need to know exactly what a remainder will be, especially with negative numbers where languages disagree.
How it works
Two definitions are computed from the dividend (a) and divisor (n):
- Truncated (JavaScript
%, C, Java): remainder = a − n × trunc(a ÷ n). Its sign follows the dividend a. - Floored (Python
%, mathematical “mod n”): remainder = ((a % n) + n) % n, always in the range 0 to |n|. Its sign follows the divisor n.
The quotient shown is the truncated integer quotient, trunc(a ÷ n). The two remainders are identical whenever both numbers share a sign; they differ only when exactly one is negative. Division by zero is reported as undefined.
Example
With a = -17 and n = 5:
- Truncated: -17 − 5 × (-3) = -17 + 15 = -2
- Floored: ((-17 % 5) + 5) % 5 = (-2 + 5) % 5 = 3
- Quotient (truncated): -3
| a mod n | Truncated | Floored |
|---|---|---|
| 17 mod 5 | 2 | 2 |
| -17 mod 5 | -2 | 3 |
| 17 mod -5 | 2 | -3 |
All arithmetic happens locally in your browser, so the numbers you enter never leave your device.