Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
float comparisons in Objective-C
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSLog(@"0.1: %@", 0.1f == 0.1 ? @"exactly equal" : @"not exactly equal");
NSLog(@"0.5: %@", 0.5f == 0.5 ? @"exactly equal" : @"not exactly equal");
NSLog(@"1.0: %@", 1.0f == 1.0 ? @"exactly equal" : @"not exactly equal");
}
}
2013-10-24 10:08:14.285 Untitled[49887:507] 0.1: not exactly equal
2013-10-24 10:08:14.301 Untitled[49887:507] 0.5: exactly equal
2013-10-24 10:08:14.302 Untitled[49887:507] 1.0: exactly equal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment