Your suffering stems from embracing the illusion that %
is a "modulo" operator. In truth, it is a remainder operator (C11 §6.5.5):
The result of the /
operator is the quotient from the division of
the first operand by the second; the result of the %
operator is the
remainder
Reject the illusion and accept the truth, and the behavior of the operator will become clear (Ibid.):
If the quotient a/b
is representable, the expression (a/b)*b + a%b
shall equal a
In your case, a/b
is -4/3
, which is -1
, hence representable. So a%b
satisfies:
(a/b)*b + a%b = a
(-1)*3 + a%b = -4
-3 + a%b = -4
a%b = -1