fltcmp

package module
v0.0.0-...-f936fb2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2018 License: MIT Imports: 1 Imported by: 0

README

fltcmp

Go Report Card Travis CI GoDoc

Go float comparison using Units in the Last Place (ULPs). You can find a good write up of the method here.

When you test for float equality, you typically aren't looking for an exact match. What you might end up doing is testing for equality with some constant error threshold. The problem with that is the behaviour is way different when comparing very small floats and very large floats. ULP testing is an alternative.

Benchmark

It's slow.

BenchmarkAlmostEqualDifferent-8         300000000                4.11 ns/op
BenchmarkAlmostEqualSame-8              300000000                3.98 ns/op
BenchmarkEpsilonSame-8                  2000000000               0.30 ns/op
BenchmarkEpsilonDifferent-8             2000000000               0.30 ns/op

Documentation

Overview

Package fltcmp implements ULP float comparison. https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlmostEqual

func AlmostEqual(a, b float64, maxUlpsDiff uint64) bool

AlmostEqual tells you how close two floats are. Make maxUlpsDiff 1 if they need be really, really close. Returns true if the ULP is within the threshold.

func AlmostEqual32

func AlmostEqual32(a, b float32, maxUlpsDiff uint32) bool

AlmostEqual32 tells you how close two floats are. Make maxUlpsDiff 1 if they need be really, really close. Returns true if the ULP is within the threshold.

func FloatDiff

func FloatDiff(a, b float64) uint64

FloatDiff finds the ULP difference between two floats.

func FloatDiff32

func FloatDiff32(a, b float32) uint32

FloatDiff32 finds the ULP difference between two floats.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL