equalsEpsilon
fun equalsEpsilon(left: Double, right: Double, relativeEpsilon: Double? = definedExternally, absoluteEpsilon: Double? = definedExternally): Boolean(source)
Determines if two values are equal using an absolute or relative tolerance test. This is useful to avoid problems due to roundoff error when comparing floating-point values directly. The values are first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed. Use this test if you are unsure of the magnitudes of left and right.
const a = Math.equalsEpsilon(0.0, 0.01, Math.EPSILON2); // true
const b = Math.equalsEpsilon(0.0, 0.1, Math.EPSILON2); // false
const c = Math.equalsEpsilon(3699175.1634344, 3699175.2, Math.EPSILON7); // true
const d = Math.equalsEpsilon(3699175.1634344, 3699175.2, Math.EPSILON9); // false
Content copied to clipboard
Return
true
if the values are equal within the epsilon; otherwise, false
.
Parameters
left
The first value to compare.
right
The other value to compare.
relativeEpsilon
The maximum inclusive delta between left
and right
for the relative tolerance test. Default value - 0
absoluteEpsilon
The maximum inclusive delta between left
and right
for the absolute tolerance test. Default value - relativeEpsilon