init()
Initializes a new BigUInt with value 0.
init(Data)
Initializes an integer from the bits stored inside a piece of Data
. The data is assumed to be in network (big-endian) byte order.
init(UnsafeRawBufferPointer)
Initialize a BigInt from bytes accessed from an UnsafeRawBufferPointer
init<T>(T)
init<T>(T)
init<T>(clamping: T)
init?(exactly: Decimal)
init?<T>(exactly: T)
init?<T>(exactly: T)
init(extendedGraphemeClusterLiteral: String)
Initialize a new big integer from an extended grapheme cluster. The cluster must consist of a decimal digit.
init(from: Decoder) throws
init(integerLiteral: UInt64)
Initialize a new big integer from an integer literal.
init(stringLiteral: StringLiteralType)
Initialize a new big integer from a decimal number represented by a string literal of arbitrary length. The string must contain only decimal digits.
init?(truncating: Decimal)
init<T>(truncatingIfNeeded: T)
init(unicodeScalarLiteral: UnicodeScalar)
Initialize a new big integer from a Unicode scalar. The scalar must represent a decimal digit.
init(words: [Word])
Initializes a new BigUInt with the specified digits. The digits are ordered from least to most significant.
init<Words>(words: Words)
static let directMultiplicationLimit: Int
Multiplication switches to an asymptotically better recursive algorithm when arguments have more words than this limit.
static var isSigned: Bool
static func compare(BigUInt, BigUInt) -> ComparisonResult
Compare a
to b
and return an NSComparisonResult
indicating their order.
static func randomInteger(lessThan: BigUInt) -> BigUInt
Create a uniformly distributed random unsigned integer that’s less than the specified limit.
static func randomInteger<RNG>(lessThan: BigUInt, using: inout RNG) -> BigUInt
Create a uniformly distributed random unsigned integer that’s less than the specified limit.
static func randomInteger(withExactWidth: Int) -> BigUInt
Create a big unsigned integer consisting of width-1
uniformly distributed random bits followed by a one bit.
static func randomInteger<RNG>(withExactWidth: Int, using: inout RNG) -> BigUInt
Create a big unsigned integer consisting of width-1
uniformly distributed random bits followed by a one bit.
static func randomInteger(withMaximumWidth: Int) -> BigUInt
Create a big unsigned integer consisting of width
uniformly distributed random bits.
static func randomInteger<RNG>(withMaximumWidth: Int, using: inout RNG) -> BigUInt
Create a big unsigned integer consisting of width
uniformly distributed random bits.
static func % (x: BigUInt, y: BigUInt) -> BigUInt
Divide x
by y
and return the remainder.
static func %= (x: inout BigUInt, y: BigUInt)
Divide x
by y
and store the remainder in x
.
static func &= (a: inout BigUInt, b: BigUInt)
Calculate the bitwise AND of a
and b
and return the result.
static func * (x: BigUInt, y: BigUInt) -> BigUInt
Multiply a
by b
and return the result.
static func *= (a: inout BigUInt, b: BigUInt)
Multiply a
by b
and store the result in a
.
static func + (a: BigUInt, b: BigUInt) -> BigUInt
Add a
and b
together and return the result.
static func += (a: inout BigUInt, b: BigUInt)
Add a
and b
together, and store the sum in a
.
static func - (a: BigUInt, b: BigUInt) -> BigUInt
Subtract b
from a
and return the result.
static func -= (a: inout BigUInt, b: BigUInt)
Subtract b
from a
and store the result in a
.
static func / (x: BigUInt, y: BigUInt) -> BigUInt
Divide x
by y
and return the quotient.
static func /= (x: inout BigUInt, y: BigUInt)
Divide x
by y
and store the quotient in x
.
static func < (a: BigUInt, b: BigUInt) -> Bool
Return true iff a
is less than b
.
static func << <Other>(lhs: BigUInt, rhs: Other) -> BigUInt
static func <<= <Other>(lhs: inout BigUInt, rhs: Other)
static func == (a: BigUInt, b: BigUInt) -> Bool
Return true iff a
is equal to b
.
static func >> <Other>(lhs: BigUInt, rhs: Other) -> BigUInt
static func >>= <Other>(lhs: inout BigUInt, rhs: Other)
static func ^= (a: inout BigUInt, b: BigUInt)
Calculate the bitwise XOR of a
and b
and return the result.
static func |= (a: inout BigUInt, b: BigUInt)
Calculate the bitwise OR of a
and b
, and store the result in a
.
static func ~ (a: BigUInt) -> BigUInt
Return the ones’ complement of a
.
var bitWidth: Int
The minimum number of bits required to represent this integer in binary.
var debugDescription: String
Return the decimal representation of this integer.
var description: String
Return the decimal representation of this integer.
var isZero: Bool
Return true iff this integer is zero.
var leadingZeroBitCount: Int
The number of leading zero bits in the binary representation of this integer in base 2^(Word.bitWidth)
. This is useful when you need to normalize a BigUInt
such that the top bit of its most significant word is 1.
var playgroundDescription: Any
Return the playground quick look representation of this integer.
var trailingZeroBitCount: Int
The number of trailing zero bits in the binary representation of this integer.
var words: Words
subscript(bitAt: Int) -> Bool
func advanced(by: BigInt) -> BigUInt
Adds n
to self
and returns the result. Traps if the result would be less than zero.
func decrement(shiftedBy: Int)
Decrement this integer by one.
func distance(to: BigUInt) -> BigInt
Returns the (potentially negative) difference between self
and other
as a BigInt
. Never traps.
func encode(to: Encoder) throws
func greatestCommonDivisor(with: BigUInt) -> BigUInt
Returns the greatest common divisor of self
and b
.
func hash(into: inout Hasher)
Append this BigUInt
to the specified hasher.
func inverse(BigUInt) -> BigUInt?
Returns the multiplicative inverse of this integer in modulo modulus
arithmetic, or nil
if there is no such number.
func isPrime(rounds: Int) -> Bool
Returns true if this integer is probably prime. Returns false if this integer is definitely not prime.
func isStrongProbablePrime(BigUInt) -> Bool
Returns true iff this integer passes the strong probable prime test for the specified base.
func multiplied(by: BigUInt) -> BigUInt
Multiply this integer by y
and return the result.
func multiplied(byWord: Word) -> BigUInt
Multiply this big integer by a single Word, and return the result.
func multiply(byWord: Word)
Multiply this big integer by a single word, and store the result in place of the original big integer.
func multiplyAndAdd(BigUInt, Word, shiftedBy: Int)
Multiply x
by y
, and add the result to this integer, optionally shifted shift
words to the left.
func power(Int) -> BigUInt
Returns this integer raised to the power exponent
.
func power(BigUInt, modulus: BigUInt) -> BigUInt
Returns the remainder of this integer raised to the power exponent
in modulo arithmetic under modulus
.
func quotientAndRemainder(dividingBy: BigUInt) -> (quotient: BigUInt, remainder: BigUInt)
Divide this integer by y
and return the resulting quotient and remainder.
func serialize() -> Data
Return a Data
value that contains the base-256 representation of this integer, in network (big-endian) byte order.
func serializeToBuffer() -> UnsafeRawBufferPointer
Return a UnsafeRawBufferPointer
buffer that contains the base-256 representation of this integer, in network (big-endian) byte order.
func signum() -> BigUInt
Returns 1
if this value is, positive; otherwise, 0
.
func squareRoot() -> BigUInt
Returns the integer square root of a big integer; i.e., the largest integer whose square isn’t greater than value
.
func subtract(BigUInt, shiftedBy: Int)
Subtract other
from this integer in place. other
is shifted shift
digits to the left before being subtracted.
func subtractReportingOverflow(BigUInt, shiftedBy: Int) -> Bool
Subtract other
from this integer in place, and return a flag indicating if the operation caused an arithmetic overflow. other
is shifted shift
digits to the left before being subtracted.
func subtracting(BigUInt, shiftedBy: Int) -> BigUInt
Subtract b
from this integer, and return the difference. b
is shifted shift
digits to the left before being subtracted.
func subtractingReportingOverflow(BigUInt) -> (partialValue: BigUInt, overflow: Bool)
Subtracts other
from self
, returning the result and a flag indicating arithmetic overflow.
func subtractingReportingOverflow(BigUInt, shiftedBy: Int) -> (partialValue: BigUInt, overflow: Bool)
Subtract other
from this integer, returning the difference and a flag indicating arithmetic overflow. other
is shifted shift
digits to the left before being subtracted.