als-statistics
Version:
Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co
14 lines (13 loc) • 419 B
JavaScript
import assert from 'node:assert/strict';
export const relEps = (eps=1e-8) => (a,b) => {
if(a === undefined && b === undefined) {
assert(true)
}
else assert.ok(
Number.isFinite(a) && Number.isFinite(b) &&
Math.abs(a - b) <= eps * (1 + Math.max(Math.abs(a), Math.abs(b))),
`Expected ~ ${b}, got ${a}`
);
}
export const approx1e8 = relEps(1e-8);
export const approx1e6 = relEps(1e-6);