2
0

math.go 429 B

123456789101112131415
  1. package util
  2. import "math"
  3. // IsApproximately returns true is a approximately equals b, within
  4. // a delta computed as a function of the size of a and b.
  5. func IsApproximately(a, b float64) bool {
  6. delta := 0.000001 * math.Max(math.Abs(a), math.Abs(b))
  7. return math.Abs(a-b) <= delta
  8. }
  9. // IsWithin returns true if a and b are within delta of each other
  10. func IsWithin(a, b, delta float64) bool {
  11. return math.Abs(a-b) <= delta
  12. }