# bigint-mod-arith - v3.2.1 Some common functions for modular arithmetic using native JS implementation of BigInt ## Table of contents ### Interfaces - [Egcd](interfaces/Egcd.md) ### Type Aliases - [PrimeFactor](API.md#primefactor) - [PrimeFactorization](API.md#primefactorization) - [PrimePower](API.md#primepower) ### Functions - [abs](API.md#abs) - [bitLength](API.md#bitlength) - [crt](API.md#crt) - [eGcd](API.md#egcd) - [gcd](API.md#gcd) - [lcm](API.md#lcm) - [max](API.md#max) - [min](API.md#min) - [modAdd](API.md#modadd) - [modInv](API.md#modinv) - [modMultiply](API.md#modmultiply) - [modPow](API.md#modpow) - [phi](API.md#phi) - [toZn](API.md#tozn) ## Type Aliases ### PrimeFactor Ƭ **PrimeFactor**: `number` \| `bigint` \| [`PrimePower`](API.md#primepower) #### Defined in [modPow.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/modPow.ts#L8) ___ ### PrimeFactorization Ƭ **PrimeFactorization**: [`bigint`, `bigint`][] #### Defined in phi.ts:1 ___ ### PrimePower Ƭ **PrimePower**: [`number` \| `bigint`, `number` \| `bigint`] #### Defined in [modPow.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/modPow.ts#L7) ## Functions ### abs ▸ **abs**(`a`): `number` \| `bigint` Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0 #### Parameters | Name | Type | | :------ | :------ | | `a` | `number` \| `bigint` | #### Returns `number` \| `bigint` The absolute value of a #### Defined in [abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/abs.ts#L8) ___ ### bitLength ▸ **bitLength**(`a`): `number` Returns the (minimum) length of a number expressed in bits. #### Parameters | Name | Type | | :------ | :------ | | `a` | `number` \| `bigint` | #### Returns `number` The bit length #### Defined in [bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/bitLength.ts#L7) ___ ### crt ▸ **crt**(`remainders`, `modulos`, `modulo?`): `bigint` Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime (no two divisors share a common factor other than 1). Provided that n_i are pairwise coprime, and a_i any integers, this function returns a solution for the following system of equations: x ≡ a_1 mod n_1 x ≡ a_2 mod n_2 ⋮ x ≡ a_k mod n_k #### Parameters | Name | Type | Description | | :------ | :------ | :------ | | `remainders` | `bigint`[] | the array of remainders a_i. For example [17n, 243n, 344n] | | `modulos` | `bigint`[] | the array of modulos n_i. For example [769n, 2017n, 47701n] | | `modulo?` | `bigint` | the product of all modulos. Provided here just to save some operations if it is already known | #### Returns `bigint` x #### Defined in crt.ts:16 ___ ### eGcd ▸ **eGcd**(`a`, `b`): [`Egcd`](interfaces/Egcd.md) An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm. Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b). **`Throws`** RangeError if a or b are <= 0 #### Parameters | Name | Type | | :------ | :------ | | `a` | `number` \| `bigint` | | `b` | `number` \| `bigint` | #### Returns [`Egcd`](interfaces/Egcd.md) A triple (g, x, y), such that ax + by = g = gcd(a, b). #### Defined in [egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/egcd.ts#L17) ___ ### gcd ▸ **gcd**(`a`, `b`): `bigint` Greatest common divisor of two integers based on the iterative binary algorithm. #### Parameters | Name | Type | | :------ | :------ | | `a` | `number` \| `bigint` | | `b` | `number` \| `bigint` | #### Returns `bigint` The greatest common divisor of a and b #### Defined in [gcd.ts:11](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/gcd.ts#L11) ___ ### lcm ▸ **lcm**(`a`, `b`): `bigint` The least common multiple computed as abs(a*b)/gcd(a,b) #### Parameters | Name | Type | | :------ | :------ | | `a` | `number` \| `bigint` | | `b` | `number` \| `bigint` | #### Returns `bigint` The least common multiple of a and b #### Defined in [lcm.ts:11](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/lcm.ts#L11) ___ ### max ▸ **max**(`a`, `b`): `number` \| `bigint` Maximum. max(a,b)==a if a>=b. max(a,b)==b if a=b. min(a,b)==a if a