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

Related tags

Utility Approximate
Overview

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.

You might also like...
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

Mechanical editing support for Package.swift manifests

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

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

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

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

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

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

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

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

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,

Releases(v1.0.1)
Owner
Christopher Blanchard
Software Engineer
Christopher Blanchard
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

HyperRedink 1.1k Dec 29, 2022
A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

Brent Mifsud 33 Oct 3, 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

Fırat Yenidünya 2 Dec 30, 2022
Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Elegant Chaos 4 Jul 20, 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

Geonu Jeon 2 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. Have the best of both worlds

async_plus 132 Jan 6, 2023
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

null 896 Dec 14, 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.

Apple 2k Dec 28, 2022
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

null 374 Jan 3, 2023
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

Zamzam Inc. 261 Dec 15, 2022