Created
November 25, 2022 08:08
-
-
Save wonderbit/a63de5e9798e7a88276a71daed786203 to your computer and use it in GitHub Desktop.
Compare nearly equal floating point values
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
import Foundation | |
extension FloatingPoint { | |
func isNearlyEqual(to value: Self, tolerance: Self = 0.00001) -> Bool { | |
return value < self + tolerance && value > self - tolerance | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment