Weird Objective-C Mod Behavior

Posted by coneybeare on Stack Overflow See other posts from Stack Overflow or by coneybeare
Published on 2009-06-13T04:05:36Z Indexed on 2010/05/09 21:08 UTC
Read the original article Hit count: 363

Filed under:
|
|
|
|

So I thought that negative numbers, when mod'ed should be put into positive space... I cant get this to happen in objective-c

I expect this:

-1 % 3 = 2
 0 % 3 = 0
 1 % 3 = 1
 2 % 3 = 2

But get this

-1 % 3 = -1
 0 % 3 = 0
 1 % 3 = 1
 2 % 3 = 2

Why is this and is there a workaround?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about modulus