# almost-equal **Repository Path**: ArkTSCentralRepository/almost-equal ## Basic Information - **Project Name**: almost-equal - **Description**: Test if two floats are almost equal - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-01 - **Last Updated**: 2026-04-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # almost-equal 基于[almost-equal](https://www.npmjs.com/package/almost-equal)原库1.1.0版本进行适配 > Checks when two floats are almost equal. ## Install ```sh ohpm install almost-equal ``` ## Usage ```javascript import AlmostEqual from "almost-equal"; const almostEqual = AlmostEqual.almostEqual; let a = 100; let 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. ### `almostEqual.FLT_EPSILON` Floating point (32-bit) epsilon ### `almostEqual.DBL_EPSILON` Double precision (64-bit) epsilon Credits ======= (c) 2013 Mikola Lysenko. MIT License