@technobuddha/library
Version:
A large library of useful functions
15 lines (14 loc) • 515 B
JavaScript
/**
* Tests whether the two values are equal to each other, within a certain
* tolerance, taking into account floating point errors (numbers within EPSILON).
*
* @param a First number to compare.
* @param b Second number to compare.
* @param __namedParameters see {@link Options}
* @default tolerance 0
* @return true if *a* and *b* are nearly equal.
*/
export function almostEquals(a, b, { tolerance = 0 } = {}) {
return Math.abs(a - b) <= (tolerance + Number.EPSILON);
}
export default almostEquals;