Approximate is a Swift package that provides implementations of floating point comparisons for the Swift ecosystem

Last update: Jun 1, 2022

Approximate

Approximate floating point equality comparisons for the Swift Programming Language.

Introduction

Approximate is a Swift package that provides implementations of floating point comparisons for the Swift ecosystem. It is generally not correct behavior to compare two floating point numbers for equality or inequality using exact equality comparisons, due to the imprecise nature of floating point arithmetic. In its place one uses approximate comparisons instead. Floating point numbers are counterintuitive creatures, so one needs to approach them differently than integers.

Usage

To use Approximate in your projects, add the following line to the dependencies list in your swift package manifest

dependencies: [
    .package(url: "https://github.com/lambdaxymox/Approximate", .branch("master")),
]

and the following line to each of your desired targets

.product(name: "Approximate", package: "Approximate")

For example, your Swift package manifest may look like

// swift-tools-version:5.6
import PackageDescription

let package = Package(
    name: "my-app",
    dependencies: [
        .package(url: "https://github.com/lambdaxymox/Approximate", from: "1.0.1"),
    ],
    targets: [
        .target(name: "my-app", dependencies: [
            .product(name: "Approximate", package: "Approximate"),
        ]),
    ]
)

Finally import the library

import Approximate

and use it in your project.

Features

This library provides the three standard forms of approximate equality comparisons for floating point numbers in Swift. These are absolute difference equality, units in last place (ULPS) equality, and relative equality.

References

Some references going in depth about comparing floating point numbers and their tricky subtleties.

GitHub

https://github.com/lambdaxymox/Approximate
You might also like...

Swift Package for Decoding RSS Feeds.

SyndiKit Swift Package built on top of XMLCoder for Decoding RSS Feeds. Check out the DocC-Built Site! Table of Contents Introduction Features Install

Mar 18, 2022

A simple Swift package for counting the Syllables in a sentence.

A simple Swift package for counting the Syllables in a sentence.

Jan 3, 2022

Azure Maps iOS SDK binary distribution for Swift Package Manager

Azure Maps iOS SDK binary distribution for Swift Package Manager

Azure Maps Control for iOS Installation In your Xcode iOS Project settings, under Project setting’s Package Dependencies, click on + button to add pac

Nov 1, 2021

Numerals is a package containing additional numeric types for the Swift programming language.

swift-numerals Numerals is a package containing additional numeric types for the Swift programming language. Contents The package currently provides t

Jun 12, 2022

Swift package adding fraction and percentage types.

swift-rationals Rationals is a package containing Fraction and Percentage types for the Swift programming language. Contents The package currently pro

Jun 12, 2022

Swift package adding measurable types.

swift-measures Measures is a package containing measurable types for the Swift programming language. Contents The package currently provides the follo

Jun 9, 2022

Swift package for accessing SF Symbols in a type safe manner.

Swift Package Information Code Coverage Swift package for accessing SF Symbols in a type safe manner. Features 💫 Contains all SF Symbols - 1.0, 2.0,

Dec 7, 2021

This is a Swift package with support for macOS that allows to start Java Jar's with the default or a custom JVM.

Jar.swift jar runner for macos Jar.swift is created and maintaned with ❥ by Sascha Muellner. What? This is a Swift package with support for macOS that

Nov 11, 2021

Units is a Swift package to manipulate, compare, and convert between physical quantities.

Units 📏 Units is a Swift package to manipulate, compare, and convert between physical quantities. This package models measurements, which are a numer

Jun 20, 2022
Related tags
Sugar is a sweetener for your Cocoa implementations.
Sugar is a sweetener for your Cocoa implementations.

Sugar is a sweetener for your Cocoa implementations. Table of Contents iOS Application Screen Simulator Keyboard Observer iOS Extensions UIView

Jun 18, 2022
WholesomeExtensions - A SPM package that provides some extensions that I like to use

WholesomeExtensions This package includes some extensions that I like to use. Yo

Jan 12, 2022
Angle is a simple Swift library that provides Angle structure representing angles.

Angle is a simple Swift library that provides Angle structure representing angles. It handles angles using circular measure by default but is al

Nov 30, 2021
Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures
Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures

Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures. Have the best of both worlds

Jun 18, 2022
MiniKeePass provides secure password storage on your phone that's compatible with KeePass.

MiniKeePass MiniKeePass provides secure password storage on your phone that's compatible with KeePass. View, Edit, and Create KeePass 1.x and 2.x file

Jun 10, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Jun 27, 2022
A command-line tool and Swift Package for generating class diagrams powered by PlantUML
A command-line tool and Swift Package for generating class diagrams powered by PlantUML

SwiftPlantUML Generate UML class diagrams from swift code with this Command Line Interface (CLI) and Swift Package. Use one or more Swift files as inp

Jun 21, 2022
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Jun 17, 2022
Swift implementation of the package url spec

PackageURL Swift implementation of the package url specification. Requirements Swift 5.3+ Usage import PackageURL let purl: PackageURL = "pkg:swift/a

Jun 14, 2022
Mechanical editing support for Package.swift manifests

Mechanical editing support for Package.swift manifests. Implements Swift Evolution proposal SE-301

Jun 9, 2022