From b84006fa2f4b720bdd191899bd0ce19e95ed2aa1 Mon Sep 17 00:00:00 2001 From: Ettore Pasquini Date: Mon, 2 Dec 2024 09:19:13 -0800 Subject: [PATCH] Allow Double to use equality minus epsilon comparison (#21) --- ...NYPLAdditions.swift => Double+NYPLAdditions.swift} | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) rename Sources/Number/{Float+NYPLAdditions.swift => Double+NYPLAdditions.swift} (67%) diff --git a/Sources/Number/Float+NYPLAdditions.swift b/Sources/Number/Double+NYPLAdditions.swift similarity index 67% rename from Sources/Number/Float+NYPLAdditions.swift rename to Sources/Number/Double+NYPLAdditions.swift index 817e4f3..3fc76b6 100644 --- a/Sources/Number/Float+NYPLAdditions.swift +++ b/Sources/Number/Double+NYPLAdditions.swift @@ -1,26 +1,23 @@ // -// StdLib+NYPLAdditions.swift -// Simplified -// // Created by Ettore Pasquini on 6/17/20. -// Copyright © 2020 NYPL. All rights reserved. +// Copyright © 2024 The New York Public Library. All Rights Reserved. // import Foundation infix operator =~= : ComparisonPrecedence -public extension Float { +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: Float, b: Float?) -> Bool { + static func =~= (a: Double, b: Double?) -> Bool { guard let b = b else { return false } - return abs(a - b) < Float.ulpOfOne + return abs(a - b) < Double.ulpOfOne } func roundTo(decimalPlaces: Int) -> String {