20th Aug 2019, 8:35 PM
UraL
4 odpowiedzi
+ 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
21st Aug 2019, 1:53 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Looks like C++ mods abs'ed numbers basically, hm?
20th Aug 2019, 9:52 PM
HonFu
HonFu - avatar
+ 1
f(6, -4) = 6 - (6/-4)* (-4) = 6 - 4 = 2
21st Aug 2019, 3:51 AM
UraL
+ 1
Hatsy Rei thanx
21st Aug 2019, 3:51 AM
UraL