Public
Edited
Mar 14, 2024
Insert cell
Insert cell
function isClose(a, b, relTol = 1e-9, absTol = 0.0) {
// NaN is not close to anything
if(isNaN(a) || isNaN(b)){
return false
}

// skips
if(a===b){
return true
}
// handles inf etc.
if(!isFinite(a) || !isFinite(b)){
return false
}
return (
// absolute(a - b) <= (atol + rtol * absolute(b))
Math.abs(a - b) <=
Math.max(relTol * Math.max(Math.abs(a), Math.abs(b)), absTol)
);
}
Insert cell
isClose(1,1)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more