- Dividend (a)
- 17
- Divisor (n)
- 5
2.000000
Open with these values2.000000
Result: 2.000000The answer is a mod n, the remainder after dividing a by n: a − n × floor(a ÷ n). This is the floored convention, so the remainder takes the sign of the divisor — −17 mod 5 is 3 here, while JavaScript and C print −2. That single difference is why people look this up.
2.000000
Open with these values3.000000
Open with these values1.500000
Open with these valuesa mod n = a − n × floor(a ÷ n)
| a, n | Quotient floor(a ÷ n) | a mod n |
|---|---|---|
| 0, 5 | 0 | 0 |
| 9.5, 2 | 4 | 1.5 |
| 17, 5 | 3 | 2 |
| 100, 7 | 14 | 2 |
| -8, 3 | -3 | 1 |
| -17, 5 | -4 | 3 |
| 17, -5 | -4 | -3 |
Divide the dividend by the divisor, round the quotient down, then subtract the divisor times that quotient from the dividend: a mod n = a − n × floor(a ÷ n). For example, 17 mod 5 = 17 − 5 × 3 = 2.
It returns the remainder left after dividing one number by another — what is left once as many whole multiples of n as fit have been taken out of a. Programmers use it for wrapping values, cycling through lists and testing divisibility.
This calculator uses the floored definition, so the remainder always takes the sign of the divisor: −17 mod 5 = 3, because floor(−17 ÷ 5) = −4 and −17 − 5 × (−4) = 3. Most programming languages use the truncated definition instead and would print −2. Always check which convention your language follows.
For positive numbers they are identical. They part company with negatives: the floored modulo matches the sign of the divisor, while the truncated remainder matches the sign of the dividend.
Modulo by zero has no standard meaning, so this calculator follows Knuth and returns the dividend unchanged: x mod 0 = x. The older calculator showed no result at all in that case. Every other divisor works, positive or negative, whole or decimal.
Information, not professional advice.
Diese Seite gibt es auch auf Deutsch.
Zu Deutsch wechseln