Swiftpack.co - lambdaxymox/Approximate as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by lambdaxymox.
lambdaxymox/Approximate v1.0.1
Approximate floating point equality comparisons for the Swift programming language.
⭐️ 0
🕓 1 year ago
.package(url: "https://github.com/lambdaxymox/Approximate.git", from: "v1.0.1")

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

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Approximate Version 1.0.1
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics