Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
clavoie committed Sep 4, 2018
1 parent ae1c82e commit 7465d6b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# mathu [![GoDoc](https://godoc.org/github.com/clavoie/mathu?status.svg)](http://godoc.org/github.com/clavoie/mathu) [![Build Status](https://travis-ci.org/clavoie/mathu.svg?branch=master)](https://travis-ci.org/clavoie/mathu) [![codecov](https://codecov.io/gh/clavoie/mathu/branch/master/graph/badge.svg)](https://codecov.io/gh/clavoie/mathu) [![Go Report Card](https://goreportcard.com/badge/github.com/clavoie/mathu)](https://goreportcard.com/report/github.com/clavoie/mathu)

Epsilon definitions for Go.
[Epsilon definitions](https://godoc.org/github.com/clavoie/mathu#pkg-constants) for Go.

```go

func Equal(f1, f2, threshold float64) bool {
f3 := math.Abs(f1 - f2)
return mathu.Zero(f3) || f3 < threshold
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:

```go
f := mathu.Float(1.23)

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

0 comments on commit 7465d6b

Please sign in to comment.