(n: bigint)
| 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 | */ |
| 39 | export 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; |
nothing calls this directly
no outgoing calls
no test coverage detected