I am not asking about this definition, but why did the language developers decide to define a module with asymmetric behavior in C ++. (I also think Java)
Suppose I want to find the smallest number greater than or equal to n, which is divided by f.
If n is positive, then I:
if(n % f) ans = n + f - n % f;
If n is negative:
ans = n - n % f;
It is clear that this definition is not the most appropriate when considering negative and positive numbers. So why is he so determined? In which case does this make sense?
"modulo 2 arithmetic", . ""
. n , ++ , % / , a b (a/b)*b + a%b a. C99 , a % b , a. (, Python) , a % b , b.
n
%
/
a
b
(a/b)*b + a%b
a % b
, , n, ++. /if n%f ( n ), ans n.
n%f
ans