BInt
public struct BInt:
SignedNumeric, // Implies Numeric, Equatable, ExpressibleByIntegerLiteral
BinaryInteger, // Implies Hashable, CustomStringConvertible, Strideable, Comparable
ExpressibleByFloatLiteral,
Sendable
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))
-
Required by protocol Numeric
Declaration
Swift
public typealias Magnitude = UInt64 -
The absolute magnitude of the integer as a UInt64.
Declaration
Swift
public var magnitude: UInt64 { get } -
Declaration
Swift
public typealias Words = [UInt] -
A collection containing the words of this value’s binary representation, in order from the least significant to most significant.
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 formatted 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) -
Declaration
Swift
public init(floatLiteral value: Double) -
Declaration
Swift
public init(integerLiteral value: Int) -
Required by protocol Numeric
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
-
String representation of the BInt in decimal format.
Declaration
Swift
public var description: String { get } -
Undocumented
Declaration
Swift
public init?(number: String, withBase base: Int) -
Undocumented
Declaration
Swift
public func asString(withBase base: Int) -> String
-
Hash value for BInt based on sign and limbs representation.
Declaration
Swift
public func hash(into hasher: inout Hasher) -
A Boolean value indicating whether this type is a signed integer type.
Declaration
Swift
public static var isSigned: Bool { 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 bits in the current binary representation of this value.
Declaration
Swift
public var bitWidth: Int { get } -
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 -
Required by protocol Numeric
Declaration
Swift
public static func += (lhs: inout BInt, rhs: BInt) -
Required by protocol Numeric
Declaration
Swift
public static func + (lhs: BInt, rhs: BInt) -> BInt
-
Negates the value by flipping its sign.
Declaration
Swift
public mutating func negate() -
Required by protocol SignedNumeric
Declaration
Swift
public prefix static func - (n: BInt) -> BInt
-
Required by protocol Numeric
Declaration
Swift
public static func - (lhs: BInt, rhs: BInt) -> BInt -
Required by protocol Numeric
Declaration
Swift
public static func -= (lhs: inout BInt, rhs: BInt)
-
Required by protocol Numeric
Declaration
Swift
public static func * (lhs: BInt, rhs: BInt) -> BInt -
Required by protocol SignedNumeric
Declaration
Swift
public static func *= (lhs: inout BInt, rhs: 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)
-
Required by protocol Equatable
Declaration
Swift
public static func == (lhs: BInt, rhs: BInt) -> Bool -
Required by protocol Comparable
Declaration
Swift
public static func < (lhs: BInt, rhs: BInt) -> Bool -
Required by protocol Comparable
Declaration
Swift
public static func > (lhs: BInt, rhs: BInt) -> Bool -
Required by protocol Comparable
Declaration
Swift
public static func <= (lhs: BInt, rhs: BInt) -> Bool -
Required by protocol Comparable
Declaration
Swift
public static func >= (lhs: BInt, rhs: BInt) -> Bool
View on GitHub
Install in Dash