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

Function canonicalInteger

src/compute-engine/numerics/numeric-bigint.ts:19–34  ·  view source on GitHub ↗
(
  n: bigint,
  exponent: number
)

Source from the content-addressed store, hash-verified

17 * where `g = gcd(a, b)` (its sign follows `a`/`b`; callers that need a
18 * non-negative `g` normalize the triple).
19 */
20export function extGcd(a: bigint, b: bigint): [bigint, bigint, bigint] {
21 let [oldR, r] = [a, b];
22 let [oldS, s] = [1n, 0n];
23 let [oldT, t] = [0n, 1n];
24 while (r !== 0n) {
25 const q = oldR / r;
26 [oldR, r] = [r, oldR - q * r];
27 [oldS, s] = [s, oldS - q * s];
28 [oldT, t] = [t, oldT - q * t];
29 }
30 return [oldR, oldS, oldT];
31}
32
33/**
34 * The modular multiplicative inverse of `a` modulo `m` (`m > 0`): the integer
35 * `x` in `[0, m)` with `a·x ≡ 1 (mod m)`, or `null` when `a` and `m` are not
36 * coprime (i.e. `gcd(a mod m, m) ≠ 1`).
37 */

Callers 1

reduceRationalSquareRootFunction · 0.90

Calls 2

bigPrimeFactorsFunction · 0.90
bigintFunction · 0.90

Tested by

no test coverage detected