Inputs
Modulo2
Ready
Dividing −7 by 3 does not have one leftover that every language agrees on. Truncating the quotient toward zero gives −2, because −2 × 3 is −6, and −7 − (−6) is −1. That −1 is the remainder: the sign follows the dividend. The modulo on this page is the non-negative residue, folded into the range from 0 up to one less than the absolute value of the divisor. For −7 and 3 that residue is 2, because −7 = −3 × 3 + 2.
Both stories are printed. Modulo 2, remainder −1, truncated quotient −2. They satisfy dividend = quotient × divisor + remainder with the truncated quotient. The modulo instead satisfies a non-negative leftover, which is what you want for clock positions, array indexes, and the day of a cycle when the step went backwards.
The divisor cannot be 0. Both inputs are integers. With a positive dividend the modulo and the remainder match: 7 divided by 3 is quotient 2, remainder 1, modulo 1. The interesting case is the negative one, which is why the sample uses −7.
Dividend −7. Divisor 3.
Modulo 2. Remainder −1. Truncated quotient −2.
Oddsock runs this in your browser. It is free, it does not upload the work, and it does not ask for an account.
The non-negative modulo is 2. The remainder that pairs with a quotient truncated toward zero is −1, and that quotient is −2.
Remainder keeps the sign of the dividend, matching the % operator in JavaScript and several other languages. Modulo here shifts that leftover by the divisor until it sits at 0 or above.
Truncation toward zero of −7 / 3 is −2.333… cut to −2. The quotient −3 is the one that pairs with modulo 2, not with remainder −1.
Yes. 7 divided by 3 has quotient 2, remainder 1, and modulo 1. The two leftovers diverge only when the dividend is negative.
Yes, as long as it is not zero. The modulo is still folded with the absolute value of the divisor so the residue is non-negative.