Skip to content

Instantly share code, notes, and snippets.

@nfreear
nfreear / floating-point-compare.js
Created July 4, 2013 13:02
Floating point Javascript: less than & greater than comparisons.
/*
http://stackoverflow.com/questions/4915462/how-should-i-do-floating-point-comparison
*/
var EPSILON = 0.000001;
function fp_less_than(A, B, Epsilon) {
Epsilon = Epsilon || EPSILON;
return (A - B < Epsilon) && (Math.abs(A - B) > Epsilon);
};