Test if two floats are nearly equal
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test added package.json Apr 3, 2013
.gitignore adding files Apr 3, 2013
LICENSE adding LICENSE May 14, 2013
README.md Update README.md Mar 8, 2016
almost_equal.js Replace FLT_EPSILON with DBL_EPSILON Mar 8, 2016
package.json 1.1.0 Mar 9, 2016



Checks when two floats are almost equal.


First install using npm:

npm install almost-equal

Then use as follows:

var almostEqual = require("almost-equal")

var a = 100
  , b = 100 + 1e-12

//Check if a == b up to float precision
console.log(almostEqual(a, b, almostEqual.FLT_EPSILON, almostEqual.FLT_EPSILON))

//Check if a == b up to double precision
console.log(almostEqual(a, b, almostEqual.DBL_EPSILON, almostEqual.DBL_EPSILON))

almostEqual(a, b[, absoluteTolerance [, relativeTolerance]])

Checks if two floats are within the given tolerances of one another using the formula:

|a - b| < max(absoluteTolerance, min(|a|, |b|) * relativeTolerance)
  • a and b are the two numbers to comapre
  • absoluteTolerance is a fixed minimal tolerance (set to 0 to ignore)
  • relativeTolerance is a tolerance that scales with a/b (set to 0 to ignore)

Returns true if a and 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