💾n.isEqual()
test if two numbers are "essentially" equal.
Last updated
Was this helpful?
test if two numbers are "essentially" equal.
Last updated
Was this helpful?
Was this helpful?
JS ⟩ value ⟩ primitive ⟩ number ⟩ Number+ext ⟩ num.isEqual()
test if two numbers are "essentially" equal.
replit - JS Number
// ⭐️ areEqualNumbers(x, y {threshold})
function areEqualNumbers(x, y, {threshold = Number.EPSILON}={}) {
return Math.abs(x - y) < threshold;
}
// ⭐️ a.isEqual(b, {threshold})
Number
💈範例:
const eps = Number.EPSILON; // 2^(-52) (very small)
const a = Math.pow(10, 300); // 10^300 (very big)
[
Number.EPSILON, // 2.220446049250313e-16 (2^(-52))