Numbers

BigNumber

  • BigNumber is an arbitrary precision integer value type. It stores a number in base 2^64 notation as an array.

    Each element of the array is called a limb, which is of type UInt64, the whole array is called limbs and has the type [UInt64]. A boolean sign variable determines if the number is positive or negative. If sign == true, then the number is smaller than 0, otherwise it is greater or equal to 0. It stores the 64 bit digits in little endian, that is, the least significant digit is stored in the array index 0:

    limbs == [] := undefined, should throw an error
    limbs == [0], sign == false := 0, defined as positive
    limbs == [0], sign == true := undefined, should throw an error
    limbs == [n] := n if sign == false, otherwise -n, given 0 <= n < 2^64
    
    limbs == [l0, l1, l2, ..., ln] :=
    (l0 * 2^(0*64)) +
    (11 * 2^(1*64)) +
    (12 * 2^(2*64)) +
    ... +
    (ln * 2^(n*64))
    
    See more

    Declaration

    Swift

    public struct BigInt:
        SignedNumeric, // Implies Numeric, Equatable, ExpressibleByIntegerLiteral
        BinaryInteger, // Implies Hashable, CustomStringConvertible, Strideable, Comparable
        ExpressibleByFloatLiteral

BigDouble