UNPKG

@thi.ng/math

Version:

Assorted common math functions & utilities

21 lines (20 loc) 326 B
const simplifyRatio = (num, denom) => { let e1 = Math.abs(num); let e2 = Math.abs(denom); while (true) { if (e1 < e2) { const t = e1; e1 = e2; e2 = t; } const r = e1 % e2; if (r) { e1 = r; } else { return [num / e2, denom / e2]; } } }; export { simplifyRatio };