What are the values of (-3)%2, 3%(-2), (-3)%(-2)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What are the values of (-3)%2, 3%(-2), (-3)%(-2)?

22nd Jan 2016, 7:05 AM
DJC
2 Answers
+ 5
Apple says "The sign of b is ignored for negative values of b. This means that a % b and a % -b always give the same result." So, the sign of a is important. if a is positive then the remainder is positive. if a is negative then the remainder is negative. if remainder is zero then signs are not important.
28th Aug 2016, 7:03 PM
Celal Aybar
Celal Aybar - avatar
+ 2
(-3)%2 = -1 3%(-2) = 1 (-3)%(-2) = -1
26th May 2016, 1:00 PM
James Flanders