Skip to content

Instantly share code, notes, and snippets.

@mkuliszkiewicz
Last active March 6, 2017 20:42
Show Gist options
  • Save mkuliszkiewicz/646566f2885157c5b58126be33563638 to your computer and use it in GitHub Desktop.
Save mkuliszkiewicz/646566f2885157c5b58126be33563638 to your computer and use it in GitHub Desktop.
Compare 2 CGFloats
extension CGFloat {
static var eps: CGFloat {
if CGFLOAT_IS_DOUBLE == 1 {
return CGFloat(DBL_EPSILON)
} else {
return CGFloat(FLT_EPSILON)
}
}
}
func epsCompare(lhs: CGFloat, rhs: CGFloat) -> Bool {
return abs(lhs - rhs) <= CGFloat.eps
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment