项目作者: clavoie

项目描述 :
Epsilon definitions for Go
高级语言: Go
项目地址: git://github.com/clavoie/mathu.git
创建时间: 2018-09-03T20:08:48Z
项目社区:https://github.com/clavoie/mathu

开源协议:MIT License

下载


mathu GoDoc Build Status codecov Go Report Card

Epsilon definitions for Go.

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

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:

  1. f := mathu.Float(1.23)
  2. if f.IsZero() { /* ... */ }
  3. if f.GteZero() { /* ... */ }
  4. if f.LteZero() { /* ... */ }
  5. if f.Equal(f2, 0.001) { /* ... */ }