
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
almost-equal
Advanced tools
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 comapreabsoluteTolerance 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.
almostEqual.FLT_EPSILONFloating point (32-bit) epsilon
almostEqual.DBL_EPSILONDouble precision (64-bit) epsilon
(c) 2013 Mikola Lysenko. MIT License
FAQs
Test if two floats are almost equal
The npm package almost-equal receives a total of 637,383 weekly downloads. As such, almost-equal popularity was classified as popular.
We found that almost-equal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.