Skip to content

isCloseUlp

isCloseUlp(a, b, maxUlps?): boolean

Defined in: packages/core/src/number/is-close-ulp.ts:23

Tests whether two numbers are within maxUlps representable steps of each other.

A test about float representation, not about a domain quantity: use it for round-trip checks, codec conformance and kernel validation. It cannot express “close to zero” — every normal number is astronomically many ULPs from 0, so only ±0 and the first few subnormals ever pass. Reach for isCloseTo whenever the tolerance means something in the caller’s units.

Slower than the other forms, since the ULP distance needs BigInt.

number

The first number to compare.

number

The second number to compare.

number = 4

The maximum number of ULPs that the two numbers can differ by to be considered close. Defaults to 4.

boolean

true if the numbers are close within the specified ULPs, false otherwise. NaN is never close to anything, including itself.