So, there are three values that a module operation can give you:
Then:
-7% 5 = 3 (math, remainder> = 0)
-7% 5 = -2 (C ++)
-7% (size_t) 5 = 4 (C ++)
Another example:
-7% 4 = 1 (math, remainder> = 0)
-7% 4 = -3 (C ++)
-7% (size_t) 4 = 1 (C ++)
When the left operand is positive, the answer between all three methods is the same. But for negative values, everyone seems to have their own methods. How is the value of module operations calculated in unsigned operands computed in C ++?
Dobob source
share