Skip to content

Instantly share code, notes, and snippets.

@Protonk
Last active December 16, 2015 13:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Protonk/5443572 to your computer and use it in GitHub Desktop.
Save Protonk/5443572 to your computer and use it in GitHub Desktop.
Hey guys, I totally fixed that floating point comparison problem.
var approx = function(a, b, eps) {
// http://en.wikipedia.org/wiki/Machine_epsilon
eps = eps || 5e-16;
return |a - b| < eps;
}
approx(0.1 * 0.2, 0.02) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment