Why is a module defined as it is in programming languages

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?

+5
source share
2 answers

"modulo 2 arithmetic", . ""

+1

. n , ++ , % / , a b (a/b)*b + a%b a. C99 , a % b , a. (, Python) , a % b , b.

, , n, ++. /if n%f ( n ), ans n.

+1

All Articles