Skip to content

Add equality minus epsilon comparison for Doubles #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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