Kevin Grittner <kgrittn@ymail.com> writes:
> Assuming that all values are integers, for:
> x = a / b;
> y = a % b;
> If b is zero either statement must generate an error.
> If a and b have the same sign, x must be positive; else x must be negative.
> It must hold that abs(x) is equal to abs(a) / abs(b).
> It must hold that ((x * b) + y) is equal to a.
Not sure about the third of those statements, but the last one is
definitely a requirement.
I think the only defensible choice, really, is that % should be defined
so that a = ((a / b) * b) + (a % b). It is perfectly reasonable to
provide other division/modulus semantics as functions, preferably in
matching pairs that also satisfy this axiom. But the two operators need
to agree, or you'll have surprised users.
regards, tom lane