The `almost-equal` package provides a robust utility for comparing two floating-point numbers (`a` and `b`) with configurable absolute and relative tolerances. It addresses the inherent precision issues in floating-point arithmetic by not relying on direct equality (`a === b`). The current stable version is 1.1.0, released in 2013, indicating a very mature and stable codebase with a minimal release cadence, primarily focusing on its original purpose without frequent updates. It differentiates itself by offering both `FLT_EPSILON` (32-bit) and `DBL_EPSILON` (64-bit) constants and a clear formula `|a - b| < max(absoluteTolerance, min(|a|, |b|) * relativeTolerance)` for precise control over the comparison logic, making it suitable for scientific and financial applications where exact float comparison is critical but direct equality checks are unreliable.
npm install almost-equalVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates comparing two floating-point numbers using `almostEqual` with both `FLT_EPSILON` and `DBL_EPSILON` for explicit tolerance settings, and also shows the default `DBL_EPSILON` tolerance for common floating-point inaccuracies.
Carefully review the `almostEqual` formula (`|a - b| < max(absoluteTolerance, min(|a|, |b|) * relativeTolerance)`) and select appropriate values based on the expected magnitude and scale of numbers being compared. For general cases, `almostEqual.DBL_EPSILON` for both tolerances is a common starting point, but domain-specific requirements may necessitate fine-tuning.
Understand that while these epsilon constants are useful defaults for relative tolerance, specific applications (e.g., high-precision scientific computing, financial calculations) often require custom absolute or relative tolerances tailored to the problem domain. Do not substitute these constants for explicit, problem-specific error bounds.
Ensure your build tooling (e.g., Webpack, Rollup, esbuild, Babel) is configured to handle CommonJS modules within an ESM project. In Node.js ESM, you might need to use `import pkg from 'almost-equal'; const almostEqual = pkg.default || pkg;` or adjust your `tsconfig.json` (for TypeScript) or `package.json` (`type: module`) settings for CJS interoperability.
No dependency data recorded yet.