-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Double to use equality minus epsilon comparison
- Loading branch information
Showing
2 changed files
with
22 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Created by Ettore Pasquini on 11/29/24. | ||
// Copyright © 2024 The New York Public Library. All Rights Reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
infix operator =~= : ComparisonPrecedence | ||
|
||
public extension Double { | ||
|
||
/// Performs equality check minus an epsilon | ||
/// - Returns: `true` if the numbers differ by less than the epsilon, | ||
/// `false` otherwise. | ||
static func =~= (a: Double, b: Double?) -> Bool { | ||
guard let b = b else { | ||
return false | ||
} | ||
|
||
return abs(a - b) < Double.ulpOfOne | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.