Skip to content

Instantly share code, notes, and snippets.

@chaudum
Created February 6, 2012 14:46
Show Gist options
  • Save chaudum/1752500 to your computer and use it in GitHub Desktop.
Save chaudum/1752500 to your computer and use it in GitHub Desktop.
Subtracting the count of 2 arrays and casting it to a float
NSArray *arr1 = [NSArray arrayWithObjects:@"1", @"2", nil];
NSLog(@"[arr1 count] %lu", [arr1 count]);
NSArray *arr2 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
NSLog(@"[arr2 count] %lu", [arr2 count]);
float diff1 = (float) ([arr1 count] - [arr2 count]);
NSLog(@"diff1: %f", diff1);
NSLog(@"UINT64_MAX: %llu", UINT64_MAX);
float diff2 = (float) [arr1 count] - (float) [arr2 count];
NSLog(@"diff2: %f", diff2);
float diff3 = (float) [arr1 count] - [arr2 count];
NSLog(@"diff3: %f", diff3);
float diff4 = [arr1 count] - (float) [arr2 count];
NSLog(@"diff4: %f", diff4);
2012-02-06 14:29:18.842 TestApp[33956:707] [arr1 count] 2
2012-02-06 14:29:18.844 TestApp[33956:707] [arr2 count] 3
2012-02-06 14:29:18.845 TestApp[33956:707] diff1: 18446744073709551616.000000
2012-02-06 14:29:18.846 TestApp[33956:707] UINT64_MAX: 18446744073709551615
2012-02-06 14:29:18.846 TestApp[33956:707] diff2: -1.000000
2012-02-06 14:29:18.847 TestApp[33956:707] diff3: -1.000000
2012-02-06 14:29:18.849 TestApp[33956:707] diff4: -1.000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment