Negative quotients and their remainders

308 Views Asked by At

Since $16 \div{-3} = -5.\overline{3}$, I thought I could also express this as $16 \div{-3} = -5\:R\:1$ or in other words $16\mod{-3} = 1$. My calculator tells my it is in fact $-2$.

Along the same lines, I see that $-16\mod{3} = 2$. So, while the true answer evaluates to $-5.\overline{3}$ again, the "remained notation" is $-6\:R\:2$ here, and $-6\:R\:-2$ in the first example.

Why do we go "past" $15$ to $18$ (or in the second example, past $-15$ to $-18$) and calculate the remainder from there?

Further warping my brain, $-16\mod{-3} = -1$, so it looks like we "stop" at $-15$ in this example.

1

There are 1 best solutions below

2
On BEST ANSWER

There are various conventions for how to define the quotient and remainder for the division algorithm when extended from naturals to integers. The remainder is uniquely determined once one defines the quotient, and usually conventions say which to round the quotient, e.g. towards $\,0\,$ or, towards the nearest integer, or towards $\,\pm\infty.$ Some programming languages provide all of the possibilities, e.g. see the floor, ceiling, round, truncate functions in Common Lisp.

A web search will turn up further discussion in many places, e.g. on Wikipedia and D. Leijen, Division and Modulus for Computer Scientists.