import { assert } from "../assert.js";
import { EPSILON } from "./EPSILON.js";

/**
 * Comparison of two numbers with a given tolerance
 * @param {number} a
 * @param {number} b
 * @param {number} [tolerance]
 * @returns {boolean}
 */
export function epsilonEquals(a, b, tolerance = EPSILON) {
    assert.isNumber(a, 'a');
    assert.isNumber(b, 'b');

    assert.isNumber(tolerance, 'tolerance');
    assert.greaterThanOrEqual(tolerance, 0, 'tolerance must be greater than 0');

    return Math.abs(a - b) <= tolerance;
}
