Say, let the dividend be -4 and the divisor be 3.
By the division theorem (or the division algorithm), we have -4 = -2 * 3 + 2 and thus the remainder is 2.
On the other hand, if we do int r = (-4) % 3;
in java, we get r = -1. I interpret this result as first find the remainder obtained from the division of the absolute values of the dividend and the divisor, then attach the sign of the dividend to it.
May I ask if my interpretation is correct? How exactly and why does the computer find the remainder in such a way? How to understand the difference between these two types of remainders?