+ 1
Explain results, plz
4 Respuestas
+ 5
https://stackoverflow.com/questions/7594508/modulo-operator-with-negative-values
"... the binary % operator yields the remainder from the division of the first expression by the second ... if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a... "
Rearranging the equation, a%b can be defined as
f(a,b) = a - (a/b)*b
For the case of a = -6 and b = 4,
f(-6,4) = -6 - (-6/4)*4
=> -6 - (-1)*4
= -6 + 4
= -2
+ 1
Looks like C++ mods abs'ed numbers basically, hm?
+ 1
f(6, -4) = 6 - (6/-4)* (-4) = 6 - 4 = 2
+ 1
Hatsy Rei thanx