Operations / Functions

BigDouble Operators

Encoding a MD5 digest of bytes to a string

BigNumber Utility Functions

  • 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.

    Declaration

    Swift

    public func factorial(_ number: BigInt) throws -> BigInt

    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)!

    Declaration

    Swift

    public func gamma(_ float: BigNumber) throws -> BigNumber

    Parameters

    float

    A BigNumber

  • Returns the multiplicative inverse of this integer in modulo modulus arithmetic, or nil if there is no such number.

    Requires

    modulus > 1

    Complexity

    O(count^3)

    Declaration

    Swift

    public func inverse(_ base: BigInt, _ modulus: BigInt) -> BigInt?

    Return Value

    If gcd(self, modulus) == 1, the value returned is an integer a < modulus such that (a * self) % modulus == 1. If self and modulus aren’t coprime, the return value is nil.

  • Gives you the least (smallest) prime factor of any integer by trial division

    Declaration

    Swift

    public func leastFactor(_ number: BigInt) -> BigInt

    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

    Declaration

    Swift

    public func ln(_ n: BigInt) -> BigDouble

    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.

    Declaration

    Swift

    public func ln(_ n: BigDouble, precision: Int = 15) -> BigDouble

    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

    Declaration

    Swift

    public func sum(_ numbers: BigNumber...) -> BigNumber

    Parameters

    numbers

    The values you want to sum

  • The sum function adds values. These values are passed as an argument

    Declaration

    Swift

    public func sum(_ numbers: [BigNumber]) -> BigNumber

    Parameters

    numbers

    The values you want to sum