Consider two numbers a
and b
.
The quotient q=a/b
and remainder r=a%b
satisfy the equation a == q*b + r
.
An (hypothetical) implementation of C89 in which -9 % 7 produces 5 is an implementation in which -9 / 7 is computed as -2.
The mathematical (Euclidian) division constrains r
to be positive and smaller than b
. C99 constrains it to be of the same sign as a
and strictly between -b
and b
.
It is all only a matter of convention.