isCloseTo
isCloseTo(
a,b,tolerance?):boolean
Defined in: packages/core/src/number/is-close-to.ts:35
Tests whether two numbers are close under a relative bound, an absolute
bound, or whichever of the two is looser: |a - b| <= max(relTol * max(|a|, |b|), absTol).
The general form, and the one to reach for by default: the relative bound
carries across scales but collapses at the origin, while the absolute bound
holds at the origin but stops meaning anything far from it. Because |d| <= max(x, y) is |d| <= x || |d| <= y, this is exactly isCloseRelative(a, b, relTol) || isCloseAbsolute(a, b, absTol), evaluated in one pass.
Symmetric, unlike NumPy’s atol + rtol * |b| — swapping the operands never
changes the answer.
No defaults: a tolerance is a claim about the computation that produced a
and b, which only the caller can make. Omitting both bounds asks for exact
equality.
Parameters
Section titled “Parameters”number
The first number to compare.
number
The second number to compare.
tolerance?
Section titled “tolerance?”The relative and absolute bounds to accept.
Returns
Section titled “Returns”boolean
true if the numbers are close under either bound, false
otherwise.