Skip to content

Instantly share code, notes, and snippets.

@cdzombak
Created January 11, 2014 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdzombak/8366662 to your computer and use it in GitHub Desktop.
Save cdzombak/8366662 to your computer and use it in GitHub Desktop.
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