Operations / Functions
-
Returns the absolute value of the given number.
Parameters
xa big double
-
round to smallest BigNumber value not less than base
-
Combinations: \frac{n!}{k! * (n - k)!}.
See
combinationsWithRepititionfor 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
aBigInt
bBigInt
-
Do not use this, extremely slow. Only for testing purposes.
Parameters
aAny BigInt
bAny BigInt
Return Value
GCD of a and b as a BigInt
-
lowest (or least) common multiple.
Parameters
aBigInt
bBigInt
-
Returns the BigDouble that is largest
-
Returns the BigDouble that is the smallest
-
Convenience function combinding addition and non-negative modulo operations
Parameters
aleft hand side of the modulo addition
bright hand side of the modulo addition
mmodulus
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
bbase
ppower
mmodulus
Return Value
pow(b, p) % m
-
Non-negative modulo operation
Parameters
aleft hand side of the module operation
mmodulus
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 afterpowor**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
aAny limbs Number
bAny 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
gammaLet’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
numberThe 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
floatA BigNumber
-
Returns the multiplicative inverse of this integer in modulo
modulusarithmetic, ornilif there is no such number.Requires
modulus > 1Complexity
O(count^3)Return Value
If
gcd(self, modulus) == 1, the value returned is an integera < modulussuch that(a * self) % modulus == 1. Ifselfandmodulusaren’t coprime, the return value isnil. -
Gives you the least (smallest) prime factor of any integer by trial division
Parameters
numberThe 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) -> IntParameters
numberThe integer you want to use
-
Very fast natural logarigthm for very large numbers
Parameters
nAny
BigIntReturn 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
nThe positive real number for which you want the natural logarithm.
precisionThe 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
numbersThe values you want to sum
-
The sum function adds values. These values are passed as an argument
Parameters
numbersThe values you want to sum
View on GitHub
Operations / Functions Reference