everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
17 lines (16 loc) • 611 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAlmostEqual = void 0;
/**
* Checks if two numbers are almost equal, within a given epsilon.
* Useful for floating point comparisons.
* @author @dailker
* @param {number} a - The first number.
* @param {number} b - The second number.
* @param {number} [epsilon=1e-10] - The allowed difference.
* @returns {boolean} True if the numbers are almost equal, false otherwise.
*/
function isAlmostEqual(a, b, epsilon = 1e-10) {
return Math.abs(a - b) <= epsilon;
}
exports.isAlmostEqual = isAlmostEqual;