Skip to content

Instantly share code, notes, and snippets.

@cevaris
Created March 9, 2015 14:09
Show Gist options
  • Save cevaris/bc331cbe970b03816c6b to your computer and use it in GitHub Desktop.
Save cevaris/bc331cbe970b03816c6b to your computer and use it in GitHub Desktop.
Golang float64 equality esitimation
var EPSILON float64 = 0.00000001
func floatEquals(a, b float64) bool {
if ((a - b) < EPSILON && (b - a) < EPSILON) {
return true
}
return false
}
@TranBaNgoc
Copy link

var EPSILON float64 = 0.00000001
func floatEquals(a, b float64) bool {
        return math.Abs(a - b) < EPSILON
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment