Skip to content

Instantly share code, notes, and snippets.

@hfossli
Created May 14, 2014 11:24
Show Gist options
  • Select an option

  • Save hfossli/4616c778bea3a334f034 to your computer and use it in GitHub Desktop.

Select an option

Save hfossli/4616c778bea3a334f034 to your computer and use it in GitHub Desktop.
CGFloatEqual
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;
}
@Apps4LifeLLC
Copy link

Apps4LifeLLC commented Apr 22, 2019

What is a suggested value for accuracy? Should it be like 0.9999f and we add more 9s to lower the tolerance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment