Created
May 14, 2014 11:24
-
-
Save hfossli/4616c778bea3a334f034 to your computer and use it in GitHub Desktop.
CGFloatEqual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL CGFloatEqual(CGFloat a, CGFloat b, CGFloat accuracy) | |
{ | |
#if CGFLOAT_IS_DOUBLE | |
if (fabs(a-b) < accuracy * DBL_EPSILON * fabs(a+b) || fabs(a-b) < DBL_MIN) | |
{ | |
return YES; | |
} | |
#else | |
if (fabs(a-b) < accuracy * FLT_EPSILON * fabs(a+b) || fabs(a-b) < FLT_MIN) | |
{ | |
return YES; | |
} | |
#endif | |
return NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is a suggested value for accuracy? Should it be like
0.9999f
and we add more 9s to lower the tolerance?