Modulo calculator
Languages disagree about the sign of a remainder for negative operands. This shows both the truncated remainder and the floored modulo.
Floored modulo
3
- Truncated remainder Takes the sign of the dividend, as in C and JavaScript.
- -2
- Floored quotient
- -4
- Truncated quotient
- -3
- Divides exactly
- 0
Show the working
- Dividend = -17
- Divisor = 5
- Floored quotient = floor(-17 / 5) = -4
- Truncated quotient = trunc(-17 / 5) = -3
- Floored modulo = mod(-17, 5) = 3
- Truncated remainder = -17 - -3 * 5 = -2
- Divides exactly = 3 == 0 ? 1 : 0 = 0
Values are shown to six significant figures here; the arithmetic itself runs on exact fractions and is only rounded where a number is printed.
Scenarios & local history
Compare a saved scenario
Recent calculations
The formula
- floored: a mod b = a - b x floor(a/b)
- truncated: a rem b = a - b x trunc(a/b)
- -17 mod 5 is 3 floored and -2 truncated.