Last active
March 6, 2017 20:42
-
-
Save mkuliszkiewicz/646566f2885157c5b58126be33563638 to your computer and use it in GitHub Desktop.
Compare 2 CGFloats
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
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