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 14d3351
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 14d3351

Please sign in to comment.