Re: modulo operation



In article <437d16b9$0$21944$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
Christian Christmann <plfriko@xxxxxxxx> wrote:

>Hi,
>
>how is the modulo operation defined when one (or both) operator(s)
>is/are negative, e.g.:
>
>7 mod (-2) = ?
>
>Thank you.
>Chris

That depends how you define integer division. The key constraint is:
div(a,b)*b + mod(a,b) = a; so
mod(a,b) = a - div(a,b)*b.

The mathematically clean form of div truncates towards -oo; e.g.
div(5, -3) = -2;
but many computer languages truncate towards 0: e.g.
div(5, -3) = -1.

--
---------------------------
| BBB b \ Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | Quidquid latine dictum sit,
| B B a a r b b | altum viditur.
| BBB aa a r bbb |
-----------------------------
.