(a: BigNum, b: BigNum)
| 9 | } |
| 10 | |
| 11 | export function lcm(a: BigNum, b: BigNum): BigNum { |
| 12 | // `lcm(0, n) = 0`: the general formula would divide by `gcd(0, 0) = 0`. |
| 13 | if (a.isZero() || b.isZero()) return BigDecimal.ZERO; |
| 14 | // The least common multiple is non-negative by convention. |
| 15 | return a.mul(b).div(gcd(a, b)).abs(); |
| 16 | } |
| 17 |