Last active
January 13, 2016 15:11
-
-
Save rochoa/5b57e57c9694741c4887 to your computer and use it in GitHub Desktop.
almost-equal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Following code was extracted from almost-equal | |
// (c) 2013 Mikola Lysenko. MIT License | |
// MIT License (MIT) | |
// See https://github.com/scijs/almost-equal/blob/93af191fe4075ee2dea94d29a26c796c26bb9cb6/almost_equal.js | |
var PRECISION_FLOAT_EPSILON = 1.19209290e-7; | |
var PRECISION_DOUBLE_EPSILON = 2.2204460492503131e-16; | |
function almostEqual(a, b, absoluteError, relativeError) { | |
absoluteError = absoluteError || PRECISION_DOUBLE_EPSILON; | |
relativeError = relativeError || PRECISION_DOUBLE_EPSILON; | |
var d = Math.abs(a - b); | |
if(d <= absoluteError) { | |
return true; | |
} | |
if(d <= relativeError * Math.min(Math.abs(a), Math.abs(b))) { | |
return true; | |
} | |
return a === b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment