Skip to content

Instantly share code, notes, and snippets.

@623637646
Last active April 15, 2020 09:33
Show Gist options
  • Save 623637646/409a751a84c1588bae9bcd8a4edf3a2d to your computer and use it in GitHub Desktop.
Save 623637646/409a751a84c1588bae9bcd8a4edf3a2d to your computer and use it in GitHub Desktop.
static CGFloat MDCFabs(CGFloat value) {
#if CGFLOAT_IS_DOUBLE
return fabs(value);
#else
return fabsf(value);
#endif
}
static BOOL MDCCGFloatEqual(CGFloat a, CGFloat b) {
const CGFloat constantK = 3;
#if CGFLOAT_IS_DOUBLE
const CGFloat epsilon = DBL_EPSILON;
const CGFloat min = DBL_MIN;
#else
const CGFloat epsilon = FLT_EPSILON;
const CGFloat min = FLT_MIN;
#endif
return (MDCFabs(a - b) < constantK * epsilon * MDCFabs(a + b) || MDCFabs(a - b) < min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment