5.0 KiB
bigint-mod-arith - v3.0.1
Some common functions for modular arithmetic using native JS implementation of BigInt
Table of contents
Interfaces
Functions
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
bitLength
▸ bitLength(a
): number
Returns the bitlength of a number
Parameters
Name | Type |
---|---|
a |
number | bigint |
Returns
number
The bit length
Defined in
eGcd
▸ eGcd(a
, b
): Egcd
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}
This excepction is thrown if a or b are less than 0
Parameters
Name | Type |
---|---|
a |
number | bigint |
b |
number | bigint |
Returns
A triple (g, x, y), such that ax + by = g = gcd(a, b).
Defined in
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
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
max
▸ max(a
, b
): number
| bigint
Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
Parameters
Name | Type |
---|---|
a |
number | bigint |
b |
number | bigint |
Returns
number
| bigint
Maximum of numbers a and b
Defined in
min
▸ min(a
, b
): number
| bigint
Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
Parameters
Name | Type |
---|---|
a |
number | bigint |
b |
number | bigint |
Returns
number
| bigint
Minimum of numbers a and b
Defined in
modInv
▸ modInv(a
, n
): bigint
Modular inverse.
throws
{RangeError}
Excpeption thorwn when a does not have inverse modulo n
Parameters
Name | Type | Description |
---|---|---|
a |
number | bigint |
The number to find an inverse for |
n |
number | bigint |
The modulo |
Returns
bigint
The inverse modulo n
Defined in
modPow
▸ modPow(b
, e
, n
): bigint
Modular exponentiation b**e mod n. Currently using the right-to-left binary method
throws
{RangeError}
Excpeption thrown when n is not > 0
Parameters
Name | Type | Description |
---|---|---|
b |
number | bigint |
base |
e |
number | bigint |
exponent |
n |
number | bigint |
modulo |
Returns
bigint
b**e mod n
Defined in
toZn
▸ toZn(a
, n
): bigint
Finds the smallest positive element that is congruent to a in modulo n
remarks
a and b must be the same type, either number or bigint
throws
{RangeError}
Excpeption thrown when n is not > 0
Parameters
Name | Type | Description |
---|---|---|
a |
number | bigint |
An integer |
n |
number | bigint |
The modulo |
Returns
bigint
A bigint with the smallest positive representation of a modulo n