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))
-
Declaration
Swift
public typealias Magnitude = UInt64
-
Declaration
Swift
public var magnitude: UInt64 { get }
-
Declaration
Swift
public typealias Words = [UInt]
-
Declaration
Swift
public var words: BInt.Words { get }
-
Returns the size of the BInt in bits.
Declaration
Swift
public var size: Int { get }
-
Returns a formated human readable string that says how much space (in bytes, kilobytes, megabytes, or gigabytes) the BInt occupies.
Declaration
Swift
public var sizeDescription: String { get }
-
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 var description: String { get }
-
Returns the BInt’s value in the given base (radix) as a string.
Declaration
Swift
public func asString(radix: Int) -> String
-
Undocumented
Declaration
Swift
public var rawValue: (sign: Bool, limbs: [UInt64]) { get }
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Declaration
Swift
public static var isSigned: Bool { get }
-
Declaration
Swift
public var bitWidth: Int { get }
-
Returns -1 if this value is negative and 1 if it’s positive; otherwise, 0.
Declaration
Swift
public func signum() -> BInt
-
The number of trailing zeros in this value’s binary representation.
Declaration
Swift
public var trailingZeroBitCount: Int { get }
-
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)
-
Declaration
Swift
public static func | (lhs: BInt, rhs: BInt) -> BInt
-
Declaration
Swift
public static func |= (lhs: inout BInt, rhs: BInt)
-
Declaration
Swift
public static func ^ (lhs: BInt, rhs: BInt) -> BInt
-
Declaration
Swift
public static func ^= (lhs: inout BInt, rhs: BInt)
-
Declaration
Swift
public prefix static func ~ (x: BInt) -> BInt
-
Undocumented
Declaration
Swift
public prefix static func + (x: BInt) -> BInt
-
Declaration
Swift
public static func += (lhs: inout BInt, rhs: BInt)
-
Declaration
Swift
public static func + (lhs: BInt, rhs: BInt) -> BInt
-
Undocumented
Declaration
Swift
public static func + (lhs: Int, rhs: BInt) -> BInt
-
Undocumented
Declaration
Swift
public static func + (lhs: BInt, rhs: Int) -> BInt
-
Undocumented
Declaration
Swift
public static func += (lhs: inout Int, rhs: BInt)
-
Undocumented
Declaration
Swift
public static func += (lhs: inout BInt, rhs: Int)
-
Declaration
Swift
public mutating mutating func negate()
-
Declaration
Swift
public prefix static func - (n: BInt) -> BInt
-
Declaration
Swift
public static func - (lhs: BInt, rhs: BInt) -> BInt
-
Undocumented
Declaration
Swift
public static func - (lhs: Int, rhs: BInt) -> BInt
-
Undocumented
Declaration
Swift
public static func - (lhs: BInt, rhs: Int) -> BInt
-
Declaration
Swift
public static func -= (lhs: inout BInt, rhs: BInt)
-
Undocumented
Declaration
Swift
public static func -= (lhs: inout Int, rhs: BInt)
-
Undocumented
Declaration
Swift
public static func -= (lhs: inout BInt, rhs: Int)
-
Declaration
Swift
public static func * (lhs: BInt, rhs: BInt) -> BInt
-
Undocumented
Declaration
Swift
public static func * (lhs: Int, rhs: BInt) -> BInt
-
Undocumented
Declaration
Swift
public static func * (lhs: BInt, rhs: Int) -> BInt
-
Declaration
Swift
public static func *= (lhs: inout BInt, rhs: BInt)
-
Undocumented
Declaration
Swift
public static func *= (lhs: inout Int, rhs: BInt)
-
Undocumented
Declaration
Swift
public static func *= (lhs: inout BInt, rhs: Int)
-
Undocumented
Declaration
Swift
public static func ** (lhs: BInt, rhs: Int) -> BInt
-
Undocumented
Declaration
Swift
public func factorial() -> BInt
-
Returns the quotient and remainder of this value divided by the given value.
Declaration
Swift
public func quotientAndRemainder(dividingBy rhs: BInt) -> (quotient: BInt, remainder: BInt)
-
Declaration
Swift
public static func / (lhs: BInt, rhs: BInt) -> BInt
-
Declaration
Swift
public static func /= (lhs: inout BInt, rhs: BInt)
-
Declaration
Swift
public static func % (lhs: BInt, rhs: BInt) -> BInt
-
Declaration
Swift
public static func %= (lhs: inout BInt, rhs: BInt)
-
Declaration
Swift
public static func == (lhs: BInt, rhs: BInt) -> Bool
-
Declaration
Swift
public static func < (lhs: BInt, rhs: BInt) -> Bool
-
Declaration
Swift
public static func > (lhs: BInt, rhs: BInt) -> Bool
-
Declaration
Swift
public static func <= (lhs: BInt, rhs: BInt) -> Bool
-
Declaration
Swift
public static func >= (lhs: BInt, rhs: BInt) -> Bool