Skip to content

Commit

Permalink
Allow Double to use equality minus epsilon comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
ettore committed Nov 30, 2024
1 parent 24dedd4 commit 46aaa61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
22 changes: 22 additions & 0 deletions Sources/Number/Double+NYPLAdditions.swift
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
}
}
30 changes: 0 additions & 30 deletions Sources/Number/Float+NYPLAdditions.swift

This file was deleted.

0 comments on commit 46aaa61

Please sign in to comment.