MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / gcd

Function gcd

src/compute-engine/numerics/numeric-bignum.ts:4–9  ·  view source on GitHub ↗
(a: BigNum, b: BigNum)

Source from the content-addressed store, hash-verified

2import { BigDecimal } from '../../big-decimal/index.js';
3
4export function gcd(a: BigNum, b: BigNum): BigNum {
5 //@todo: https://github.com/Yaffle/bigint-gcd/blob/main/gcd.js
6 console.assert(a.isInteger() && b.isInteger());
7 while (!b.isZero()) [a, b] = [b, a.mod(b)];
8 return a.abs();
9}
10
11export function lcm(a: BigNum, b: BigNum): BigNum {
12 // `lcm(0, n) = 0`: the general formula would divide by `gcd(0, 0) = 0`.

Callers 1

lcmFunction · 0.70

Calls 5

assertMethod · 0.80
modMethod · 0.80
isZeroMethod · 0.65
absMethod · 0.65
isIntegerMethod · 0.45

Tested by

no test coverage detected