Operations / Functions
-
Returns the absolute value of the given number.
Parameters
x
a big double
-
round to smallest BigNumber value not less than base
-
Combinations: \frac{n!}{k! * (n - k)!}.
See
combinationsWithRepitition
for the other method.Order matters, repetition allowed.
Declaration
Swift
public func combinations(_ n: Int, _ k: Int) throws -> BigInt
-
Combinations with repetitions: \frac{(n + k - 1)!}{k! * (n - 1)!}.
Order matters, repetition allowed.
Declaration
Swift
public func combinationsWithRepetitions(_ n: Int, _ k: Int) throws -> BigInt
-
round to largest BigNumber value not greater than base
-
greatest common divisor.
Parameters
a
BigInt
b
BigInt
-
Do not use this, extremely slow. Only for testing purposes.
Parameters
a
Any BigInt
b
Any BigInt
Return Value
GCD of a and b as a BigInt
-
lowest (or least) common multiple.
Parameters
a
BigInt
b
BigInt
-
Returns the BigDouble that is largest
-
Returns the BigDouble that is the smallest
-
Convenience function combinding addition and non-negative modulo operations
Parameters
a
left hand side of the modulo addition
b
right hand side of the modulo addition
m
modulus
Return Value
nnmod(a + b, m)
-
Quick exponentiation/modulo algorithm FIXME: for security, this should use the constant-time Montgomery algorithm to thwart timing attacks
Parameters
b
base
p
power
m
modulus
Return Value
pow(b, p) % m
-
Non-negative modulo operation
Parameters
a
left hand side of the module operation
m
modulus
Return Value
r := a % b such that 0 <= r < abs(m)
-
Permutations:
$\frac{n!}{(n-k)!}
Order matters, repetition allowed.
Declaration
Swift
public func permutations(_ n: Int, _ k: Int) throws -> BigInt
-
Permutations with repetition: n^k
Order matters, repetition allowed.
Declaration
Swift
public func permutationsWithRepitition(_ n: Int, _ k: Int) -> BigInt
-
Returns a BigDouble number raised to a given power.
Warning
This may take a while -
Returns a BigDouble number raised to a given power.
Warning
This may take a while -
Warning
This may take a while. This is only precise up until precision. When comparing results afterpow
or**
usenearlyEqual
-
The binary GCD algorithm, also known as Stein’s algorithm, is an algorithm that computes the greatest common divisor of two nonnegative integers. Stein’s algorithm uses simpler arithmetic operations than the conventional Euclidean algorithm; it replaces division with arithmetic shifts, comparisons, and subtraction.
Parameters
a
Any limbs Number
b
Any limbs Numbers
Return Value
GCD of a and b as a Limbs
-
Undocumented
-
Returns the factorial of a number. The factorial of a number is equal to 1*2*3*…* number.
This relies on Lanczos approximation, provided by
gamma
Let’s say you have six bells, each with a different tone, and you want to find the number of unique sequences in which each bell can be rung once. In this example, you are calculating the factorial of six. In general, use a factorial to count the number of ways in which a group of distinct items can be arranged (also called permutations). To calculate the factorial of a number, use this function.
Parameters
number
The nonnegative number for which you want the factorial. If number is not an integer, it is truncated.
-
The gamma function (represented by \Gamma, the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers except the non-positive integers. For any positive integer n: \Gamma (n)=(n-1)!
Parameters
float
A BigNumber
-
Returns the multiplicative inverse of this integer in modulo
modulus
arithmetic, ornil
if there is no such number.Requires
modulus > 1Complexity
O(count^3)Return Value
If
gcd(self, modulus) == 1
, the value returned is an integera < modulus
such that(a * self) % modulus == 1
. Ifself
andmodulus
aren’t coprime, the return value isnil
. -
Gives you the least (smallest) prime factor of any integer by trial division
Parameters
number
The integer you want to use
-
Gives you the least (smallest) prime factor of any integer by trial division
Declaration
Swift
public func leastFactor(_ number: Int) -> Int
Parameters
number
The integer you want to use
-
Very fast natural logarigthm for very large numbers
Parameters
n
Any
BigInt
Return Value
\ln(n)
-
Returns the natural logarithm of a number. Natural logarithms are based on the constant e (2.71828182845904)
LN is the inverse of the EXP function.
Parameters
n
The positive real number for which you want the natural logarithm.
precision
The precision you want to use (number of cycles). Higher precision means better result, but slower compute time
-
The sum function adds values. These values are passed as an argument
Parameters
numbers
The values you want to sum
-
The sum function adds values. These values are passed as an argument
Parameters
numbers
The values you want to sum