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

Function reducedInteger

src/compute-engine/numerics/numeric-bigint.ts:36–40  ·  view source on GitHub ↗
(n: bigint)

Source from the content-addressed store, hash-verified

34 * The modular multiplicative inverse of `a` modulo `m` (`m ≠ 0`): the integer
35 * `x` with `a·x ≡ 1 (mod m)`, or `null` when `a` and `m` are not coprime
36 * (i.e. `gcd(a mod m, m) ≠ 1`). `x` takes the sign of `m`, as `Mod` does:
37 * `modularInverse(3n, -7n)` is `-2n`.
38 */
39export function modularInverse(a: bigint, m: bigint): bigint | null {
40 if (m === 0n) return null;
41 if (m === 1n || m === -1n) return 0n;
42 const absM = m < 0n ? -m : m;
43 const base = ((a % absM) + absM) % absM;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected