Skip to content

Commit b84006f

Browse files
authored
Allow Double to use equality minus epsilon comparison (#21)
1 parent 24dedd4 commit b84006f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Sources/Number/Float+NYPLAdditions.swift renamed to Sources/Number/Double+NYPLAdditions.swift

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
//
2-
// StdLib+NYPLAdditions.swift
3-
// Simplified
4-
//
52
// Created by Ettore Pasquini on 6/17/20.
6-
// Copyright © 2020 NYPL. All rights reserved.
3+
// Copyright © 2024 The New York Public Library. All Rights Reserved.
74
//
85

96
import Foundation
107

118
infix operator =~= : ComparisonPrecedence
129

13-
public extension Float {
10+
public extension Double {
1411

1512
/// Performs equality check minus an epsilon
1613
/// - Returns: `true` if the numbers differ by less than the epsilon,
1714
/// `false` otherwise.
18-
static func =~= (a: Float, b: Float?) -> Bool {
15+
static func =~= (a: Double, b: Double?) -> Bool {
1916
guard let b = b else {
2017
return false
2118
}
2219

23-
return abs(a - b) < Float.ulpOfOne
20+
return abs(a - b) < Double.ulpOfOne
2421
}
2522

2623
func roundTo(decimalPlaces: Int) -> String {

0 commit comments

Comments
 (0)