Modulo operator in Objective-C returns the wrong result
- by Greg Maletic
I'm a little freaked out by the results I'm getting when I do modulo arithmetic in Objective-C. -1 % 3 is coming out to be -1, which isn't the right answer: according to my understanding, it should be 2. -2 % 3 is coming out to -2, which also isn't right: it should be 1.
Is there another method I should be using besides the % operator to get the correct result?