Skip to content

Instantly share code, notes, and snippets.

@nfreear
nfreear / floating-point-compare.js
Created Jul 4, 2013
Floating point Javascript: less than & greater than comparisons.
View floating-point-compare.js
/*
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);
};
You can’t perform that action at this time.