Skip to content

Instantly share code, notes, and snippets.

@wonderbit
Created November 25, 2022 08:08
Show Gist options
  • Save wonderbit/a63de5e9798e7a88276a71daed786203 to your computer and use it in GitHub Desktop.
Save wonderbit/a63de5e9798e7a88276a71daed786203 to your computer and use it in GitHub Desktop.
Compare nearly equal floating point values
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