How this calculation works
A calendar or repeating cycle often needs a nonnegative remainder. Truncating −17/5 toward zero instead gives −3 and a negative remainder.
a = bq + r, where q = floor(a/b) and 0 ≤ r < bA worked example
−17 = 5 × (−4) + 3, so the quotient is −4 and the remainder is 3.
Good to know
The divisor is positive. Some languages use a quotient truncated toward zero.
Reference: OpenStax Prealgebra (opens in a new tab) ↗
Decompose a negative dividend
Divide −17 by the positive divisor 5. The exact quotient is −3.4. Taking its floor gives q = −4, so the multiple at or below −17 is 5 × (−4) = −20. The remainder is the distance from that multiple up to the dividend, −17 − (−20) = 3.
Put the parts back together to check the result. Five groups of the quotient contribute −20, and adding the remainder gives −20 + 3 = −17. The defining constraints are a = bq + r and 0 ≤ r < b. These conditions determine a unique quotient and remainder when the divisor is positive.
Recognize different programming conventions
Some programming operations truncate the quotient toward zero. Under that convention −17 divided by 5 gives quotient −3 and remainder −2. The identity still holds because −15 − 2 = −17, but the remainder is negative. This calculator uses the floor convention so that every remainder lies from zero through b − 1.
A nonnegative remainder is useful for repeating positions. Moving −17 positions around a cycle of length 5 lands at index 3 when indices run from 0 to 4. The Absolute value calculator can show a magnitude, but taking the absolute value of a language remainder would give 2 here and would produce the wrong cycle position.
A few questions, answered
What if the dividend is exactly divisible?
The remainder is zero. For −20 and divisor 5, the quotient is −4 and −20 = 5 × (−4) + 0.
Can the divisor be zero?
Division by zero has no quotient-remainder decomposition of this form. The field requires a positive integer divisor.