Guest

Weird Objective-C Mod Behavior

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 0.17 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. -1 % 3 = 2
  2.  0 % 3 = 0
  3.  1 % 3 = 1
  4.  2 % 3 = 2
  5.        
  6. -1 % 3 = -1
  7.  0 % 3 = 0
  8.  1 % 3 = 1
  9.  2 % 3 = 2
  10.        
  11. result = n % 3;
  12. if( result < 0 ) result += 3;
  13.        
  14. result = (n+1002) % 3;