2

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 Answers1

4

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.

Bill Dubuque
  • 272,048
  • To confirm I understand correctly: when the quotient is negative, there are various conventions as to whether the remainder is calculated, whether from the floor or ceiling? And here the calculator is using the floor function as floor(-5.3) = -6? – moon prism power Mar 28 '14 at 20:05
  • @rkarbowski Yes, follow the links for more. – Bill Dubuque Mar 28 '14 at 20:34