BInt

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

BInt 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))
  • Create an instance initialized to an integer value.

    Declaration

    Swift

    public init(_ z: Int)
  • Create an instance initialized to an unsigned integer value.

    Declaration

    Swift

    public init(_ n: UInt)
  • Create an instance initialized to a string value.

    Declaration

    Swift

    public init?(_ str: String)
  • Create an instance initialized to a string with the value of mathematical numerical system of the specified radix (base). So for example, to get the value of hexadecimal string radix value must be set to 16.

    Declaration

    Swift

    public init?(_ number: String, radix: Int)
  • Create an instance initialized to a string with the value of mathematical numerical system of the specified radix (base). You have to specify the base as a prefix, so for example, 0b100101010101110 is a vaild input for a binary number. Currently, hexadecimal (0x), octal (0o) and binary (0b) are supported.

    Declaration

    Swift

    public init?(prefixedNumber number: String)
  • Declaration

    Swift

    public init(floatLiteral value: Double)
  • Declaration

    Swift

    public init(integerLiteral value: Int)
  • Declaration

    Swift

    public init?<T>(exactly source: T) where T : BinaryInteger
  • Creates an integer from the given floating-point value, rounding toward zero.

    Declaration

    Swift

    public init<T>(_ source: T) where T : BinaryFloatingPoint
  • Creates a new instance from the given integer.

    Declaration

    Swift

    public init<T>(_ source: T) where T : BinaryInteger
  • Creates a new instance with the representable value that’s closest to the given integer.

    Declaration

    Swift

    public init<T>(clamping source: T) where T : BinaryInteger
  • Creates an integer from the given floating-point value, if it can be represented exactly.

    Declaration

    Swift

    public init?<T>(exactly source: T) where T : BinaryFloatingPoint
  • Creates a new instance from the bit pattern of the given instance by sign-extending or truncating to fit this type.

    Declaration

    Swift

    public init<T>(truncatingIfNeeded source: T) where T : BinaryInteger
  • Declaration

    Swift

    public static func << <T>(lhs: BInt, rhs: T) -> BInt where T : BinaryInteger
  • Declaration

    Swift

    public static func <<= <T>(lhs: inout BInt, rhs: T) where T : BinaryInteger
  • Declaration

    Swift

    public static func >> <T>(lhs: BInt, rhs: T) -> BInt where T : BinaryInteger
  • Declaration

    Swift

    public static func >>= <T>(lhs: inout BInt, rhs: T) where T : BinaryInteger
  • Returns the result of performing a bitwise AND operation on the two given values.

    Declaration

    Swift

    public static func & (lhs: BInt, rhs: BInt) -> BInt
  • Stores the result of performing a bitwise AND operation on the two given values in the left-hand-side variable.

    Declaration

    Swift

    public static func &= (lhs: inout BInt, rhs: BInt)