Relative difference
64-bitThe fraction by which a coarse result differs from the refined result.
|a − b| ÷ |b|
Divides by |refined| and skips zero and non-finite values, so there is no division by zero. The worst value is a plain maximum.
/**
* How far a coarse answer may be from the refined one. Used by the tests and the panel's note: the fraction |coarse − refined| / |refined|
* for each number the two results share, and the worst of them.
*/
export function spread(coarse, refined, keys) {
const out = {};
let worst = 0;
for (const k of keys) {
const a = coarse[k], b = refined[k];
if (!Number.isFinite(a) || !Number.isFinite(b) || b === 0) continue;
out[k] = Math.abs(a - b) / Math.abs(b);
if (out[k] > worst) worst = out[k];
}
return { by: out, worst };
}