Skip to content

Instantly share code, notes, and snippets.

@letsspeak
Created October 25, 2012 05:26
Show Gist options
  • Save letsspeak/3950545 to your computer and use it in GitHub Desktop.
Save letsspeak/3950545 to your computer and use it in GitHub Desktop.
NSUInteger(unsigned int) subtraction results
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSUInteger a = 5, b = 10;
NSInteger c = 8;
NSLog(@" a - b = %d", a - b);
// a - b = -5
NSLog(@"(a - b <= 0) is %@", (a - b <= 0) ? @"true" : @"false");
// (a - b <= 0) is false
NSLog(@"((NSInteger(a - b) <= 0) is %@", ((NSInteger)(a - b) <= 0) ? @"true" : @"false");
// ((NSInteger(a - b) <= 0) is true
NSLog(@"(((NSInteger)a - (NSInteger)b) <= 0) is %@", (((NSInteger)a - (NSInteger)b) <= 0) ? @"true" : @"false");
// (((NSInteger)a - (NSInteger)b) <= 0) is true
NSLog(@"((b - c) <= 0) is %@", ((b - c) <= 0) ? @"true" : @"false");
// ((b - c) <= 0) is false
NSLog(@"((c - b) <= 0) is %@", ((c - b) <= 0) ? @"true" : @"false");
// ((c - b) <= 0) is false
NSLog(@"((NSInteger)(c - b) <= 0) is %@", ((NSInteger)(c - b) <= 0) ? @"true" : @"false");
// ((NSInteger)(c - b) <= 0) is true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment