Test if two floats are almost equal
Checks when two floats are almost equal.
First install using npm:
npm install almost-equal
Then use as follows:
var almostEqual =var a = 100b = 100 + 1e-12//Check if a == b up to float precisionconsole//Check if a == b up to double precisionconsole
Checks if two floats are within the given tolerances of one another using the formula:
|a - b| < max(absoluteTolerance, min(|a|, |b|) * relativeTolerance)
bare the two numbers to comapre
absoluteToleranceis a fixed minimal tolerance (set to 0 to ignore)
relativeToleranceis a tolerance that scales with a/b (set to 0 to ignore)
b are approximately equal.
If tolerance argument is omitted,
almostEqual.DBL_EPSILON value is used by default.
Floating point (32-bit) epsilon
Double precision (64-bit) epsilon
(c) 2013 Mikola Lysenko. MIT License