
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
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
Math.js is a comprehensive math library for JavaScript and Node.js. It includes a function 'math.equal' that can be used to compare numbers, but it is more general-purpose and includes a wide range of mathematical functions and utilities. Compared to 'almost-equal', 'mathjs' offers more features but might be overkill if you only need to compare numbers for approximate equality.
Decimal.js is a library for arbitrary-precision decimal arithmetic. It provides methods for precise calculations and comparisons, including approximate equality checks. While 'almost-equal' is focused on floating-point comparisons, 'decimal.js' offers more precision and is suitable for applications requiring high precision in arithmetic operations.
FAQs
Test if two floats are almost equal
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.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.