Skip to content

clavoie/mathu

Repository files navigation

mathu GoDoc Build Status codecov Go Report Card

Epsilon definitions for Go.

func Equal(f1, f2, threshold float64) bool {
	f3 := math.Abs(f1 - f2)
	return mathu.Zero(f3) || f3 <= threshold
}

Dependency Injection

The epsilon constants as well as all top level package functions are wrapped in an interface if you would prefer to inject them into your code rather than referencing the package directly.

Floats

A wrapper type is provided around float64 that integrates with the epsilon constants and testing for zero:

f := mathu.Float(1.23)

if f.IsZero() {	/* ... */ }
if f.GteZero() { /* ... */ }
if f.LteZero() { /* ... */ }
if f.Equal(f2, 0.001) { /* ... */ }