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

Function rationalGcd

src/compute-engine/numerics/rationals.ts:208–221  ·  view source on GitHub ↗
(lhs: Rational, rhs: Rational)

Source from the content-addressed store, hash-verified

206}
207
208export function rationalGcd(lhs: Rational, rhs: Rational): Rational {
209 if (isMachineRational(lhs) && isMachineRational(rhs)) {
210 if (lhs[1] === 1 && rhs[1] === 1) return [gcd(lhs[0], rhs[0]), 1];
211 return [gcd(lhs[0], rhs[0]), lcm(lhs[1], rhs[1])];
212 }
213
214 if (lhs[1] === 1 && rhs[1] === 1)
215 return [bigGcd(BigInt(lhs[0]), BigInt(rhs[0])), BigInt(1)];
216
217 return [
218 bigGcd(BigInt(lhs[0]), BigInt(rhs[0])),
219 bigLcm(BigInt(lhs[1]), BigInt(rhs[1])),
220 ] as Rational;
221}
222
223// export function rationalLcm(
224// [a, b]: [number, number],

Callers 2

commonTermsFunction · 0.90
gcdMethod · 0.90

Calls 4

gcdFunction · 0.90
lcmFunction · 0.90
isMachineRationalFunction · 0.85
bigGcdFunction · 0.85

Tested by

no test coverage detected