https://github.com/clavoie/mathu
Epsilon definitions for Go
https://github.com/clavoie/mathu
epsilon go golang utilities
Last synced: about 2 months ago
JSON representation
Epsilon definitions for Go
- Host: GitHub
- URL: https://github.com/clavoie/mathu
- Owner: clavoie
- License: mit
- Created: 2018-09-03T20:08:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-04T12:21:26.000Z (over 6 years ago)
- Last Synced: 2025-04-12T00:49:42.529Z (about 2 months ago)
- Topics: epsilon, go, golang, utilities
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mathu [](http://godoc.org/github.com/clavoie/mathu) [](https://travis-ci.org/clavoie/mathu) [](https://codecov.io/gh/clavoie/mathu) [](https://goreportcard.com/report/github.com/clavoie/mathu)
[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
}
```## 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) { /* ... */ }
```