*=(_:_:)
x = x * y
static func *= (x: inout BInt, y: Int)
x = x * y
static func *= (x: inout BInt, y: Int)
import BigInt
Signed integers and fractions of unbounded size
struct BInt
The BInt structure
@frozen struct Int
A signed integer value type.
static func * (x: BInt, y: BInt) -> BInt
Multiplication
static func * (x: BInt, y: Int) -> BInt
Multiplication
static func * (x: Int, y: BInt) -> BInt
Multiplication
static func *= (x: inout BInt, y: BInt)
x = x * y
init?(_ d: Double)
Constructs a BInt
from a decimal value, nil
if d
is infinite or NaN
init(_ x: Int)
Constructs a BInt
from an Int
value
init<T>(_ source: T) where T : BinaryFloatingPoint
init<T>(_ source: T) where T : BinaryInteger
init(_ magnitude: Limbs, _ isNegative: Bool = false)
Constructs a BInt
from magnitude and sign
init?(_ x: String, radix: Int = 10)
Constructs a BInt
from a String value and radix, nil
if x
does not designate an integer in the given radix
init(bitWidth: Int)
Constructs a uniformly distributed random BInt
in the range 0 ..< 2 ^ bitWidth
init<T>(clamping source: T) where T : BinaryInteger
init?<T>(exactly source: T) where T : BinaryFloatingPoint
init?<T>(exactly source: T) where T : BinaryInteger
init(from decoder: any Decoder) throws
init(integerLiteral value: StaticBigInt)
Constructs a BInt from a StaticBigInt
init(magnitude x: Bytes)
Constructs a BInt
from a big-endian magnitude byte array
init(signed x: Bytes)
Constructs a BInt
from a big-endian 2’s complement byte array
init<T>(truncatingIfNeeded source: T) where T : BinaryInteger
static let EIGHT: BInt
BInt(8)
static let FIVE: BInt
BInt(5)
static let FOUR: BInt
BInt(4)
static let NINE: BInt
BInt(9)
static let ONE: BInt
BInt(1)
static let SEVEN: BInt
BInt(7)
static let SIX: BInt
BInt(6)
static let TEN: BInt
BInt(10)
static let THREE: BInt
BInt(3)
static let TWO: BInt
BInt(2)
static let ZERO: BInt
BInt(0)
static var isSigned: Bool { get }
static func binomial(_ n: Int, _ k: Int) -> BInt
Compute binomial coefficient n
over k
static func factorial(_ n: Int) -> BInt
Factorial function
static func fibonacci(_ n: Int) -> BInt
n’th Fibonacci number
static func fibonacci2(_ n: Int) -> (BInt, BInt)
Fibonacci pair, n’th and n’th + 1 Fibonacci number
static func lucas(_ n: Int) -> BInt
n’th Lucas number
static func lucas2(_ n: Int) -> (BInt, BInt)
Lucas pair, n’th and n’th + 1 Lucas number
static func primorial(_ n: Int) -> BInt
Product of primes up to n
static func probablePrime(_ bitWidth: Int, _ p: Int = 30) -> BInt
A probable prime number with a given bitwidth
var _magnitude: Limbs { get }
The magnitude limb array
var abs: BInt { get }
The absolute value of self
var bitWidth: Int { get }
The number of bits in the binary representation of the magnitude of self
. 0 if self
= 0
var description: String { get }
Base 10 string value of self
var isEven: Bool { get }
Is true
if self
is even, false
if self
is odd
var isNegative: Bool { get }
The sign, true
if self
< 0, false
if self
>= 0
var isNotZero: Bool { get }
Is false
if self
= 0, true
otherwise
var isOdd: Bool { get }
Is true
if self
is odd, false
if self
is even
var isOne: Bool { get }
Is true
if self
= 1, false
otherwise
var isPositive: Bool { get }
Is true
if self
> 0, false
otherwise
var isPow2: Bool { get }
Is true
if self
is a power of 2: 1, 2, 4, 8 …, false
otherwise
var isZero: Bool { get }
Is true
if self
= 0, false
otherwise
var leadingZeroBitCount: Int { get }
The number of leading zero bits in the magnitude of self
. 0 if self
= 0
var magnitude: BInt { get }
var population: Int { get }
The number of 1 bits in the magnitude of self
var signum: Int { get }
Is 0 if self
= 0, 1 if self
> 0, and -1 if self
< 0
var trailingZeroBitCount: Int { get }
The number of trailing zero bits in the magnitude of self
. 0 if self
= 0
var words: [UInt] { get }
static func != (x: BInt, y: BInt) -> Bool
Not equal
static func != (x: BInt, y: Int) -> Bool
Not equal
static func != (x: Int, y: BInt) -> Bool
Not equal
static func % (x: BInt, y: BInt) -> BInt
Remainder
static func % (x: BInt, y: Int) -> BInt
Remainder
static func % (x: Int, y: BInt) -> BInt
Remainder
static func %= (x: inout BInt, y: BInt)
x = x % y
static func %= (x: inout BInt, y: Int)
x = x % y
static func & (x: BInt, y: BInt) -> BInt
Bitwise and
operator - behaves as if two’s complement representation were used
static func &= (x: inout BInt, y: BInt)
x = x & y
static func ** (a: BInt, x: Int) -> BInt
Exponentiation
static func + (x: BInt) -> BInt
Prefix plus
static func + (x: BInt, y: BInt) -> BInt
Addition
static func + (x: BInt, y: Int) -> BInt
Addition
static func + (x: Int, y: BInt) -> BInt
Addition
static func += (x: inout BInt, y: BInt)
x = x + y
static func += (x: inout BInt, y: Int)
x = x + y
static func - (x: BInt) -> BInt
Negation
static func - (x: BInt, y: BInt) -> BInt
Subtraction
static func - (x: BInt, y: Int) -> BInt
Subtraction
static func - (x: Int, y: BInt) -> BInt
Subtraction
static func -= (x: inout BInt, y: BInt)
x = x - y
static func -= (x: inout BInt, y: Int)
x = x - y
static func / (x: BInt, y: BInt) -> BInt
Division
static func / (x: BInt, y: Int) -> BInt
Division
static func / (x: Int, y: BInt) -> BInt
Division
static func /= (x: inout BInt, y: BInt)
x = x / y
static func /= (x: inout BInt, y: Int)
x = x / y
static func < (x: BInt, y: BInt) -> Bool
Less than
static func < (x: BInt, y: Int) -> Bool
Less than
static func < (x: Int, y: BInt) -> Bool
Less than
static func << (x: BInt, n: Int) -> BInt
Logical left shift
static func <<= (x: inout BInt, n: Int)
x = x << n
static func <<= <RHS>(lhs: inout BInt, rhs: RHS) where RHS : BinaryInteger
static func <= (x: BInt, y: BInt) -> Bool
Less than or equal
static func <= (x: BInt, y: Int) -> Bool
Less than or equal
static func <= (x: Int, y: BInt) -> Bool
Less than or equal
static func == (x: BInt, y: BInt) -> Bool
Equal
static func == (x: BInt, y: Int) -> Bool
Equal
static func == (x: Int, y: BInt) -> Bool
Equal
static func > (x: BInt, y: BInt) -> Bool
Greater than
static func > (x: BInt, y: Int) -> Bool
Greater than
static func > (x: Int, y: BInt) -> Bool
Greater than
static func >= (x: BInt, y: BInt) -> Bool
Greater than or equal
static func >= (x: BInt, y: Int) -> Bool
Greater than or equal
static func >= (x: Int, y: BInt) -> Bool
Greater than or equal
static func >> (x: BInt, n: Int) -> BInt
Logical right shift
static func >>= (x: inout BInt, n: Int)
x = x >> n
static func >>= <RHS>(lhs: inout BInt, rhs: RHS) where RHS : BinaryInteger
static func ^ (x: BInt, y: BInt) -> BInt
Bitwise xor
operator - behaves as if two’s complement representation were used
static func ^= (x: inout BInt, y: BInt)
x = x ^ y
static func | (x: BInt, y: BInt) -> BInt
Bitwise or
operator - behaves as if two’s complement representation were used
static func |= (x: inout BInt, y: BInt)
x = x | y
static func ~ (x: BInt) -> BInt
Bitwise not
operator - behaves as if two’s complement arithmetic were used
func asDouble() -> Double
self
as a Double
func asInt() -> Int?
self
as an Int
func asMagnitudeBytes() -> Bytes
Byte array representation of magnitude value
func asSignedBytes() -> Bytes
Byte array representation of 2’s complement value
func asString(radix: Int = 10, uppercase: Bool = false) -> String
self
as a String
with a given radix
mutating func clearBit(_ n: Int)
Clear a specified bit - a no-op if bit number < 0
func expMod(_ x: BInt, _ m: BInt) -> BInt
Modular exponentiation - BInt version
func expMod(_ x: BInt, _ m: Int) -> Int
Modular exponentiation - Int version
mutating func flipBit(_ n: Int)
Invert a specified bit - a no-op if bit number < 0
func gcd(_ x: BInt) -> BInt
Greatest common divisor - BInt version
func gcd(_ x: Int) -> BInt
Greatest common divisor - Int version
func gcdExtended(_ x: BInt) -> (g: BInt, a: BInt, b: BInt)
Extended greatest common divisor - BInt version
func gcdExtended(_ x: Int) -> (g: BInt, a: BInt, b: BInt)
Extended greatest common divisor - Int version
func isPerfectRoot() -> Bool
Check whether self
is a perfect root, that is, for some integer x
and n
> 1 self
= x^n
func isPerfectSquare() -> Bool
Check whether self
is a perfect square, that is, for some integer x
, self
= x^2
func isProbablyPrime(_ p: Int = 30) -> Bool
Checks whether self
is prime using the Miller-Rabin algorithm
func jacobiSymbol(_ m: Int) -> Int
Jacobi symbol - Int version. If m
is an odd prime, this is also the Legendre symbol
func jacobiSymbol(_ m: BInt) -> Int
Jacobi symbol - BInt version. If m is an odd prime, this is also the Legendre symbol
func kroneckerSymbol(_ m: Int) -> Int
Kronecker symbol - Int version. If m
is positive and odd, this is also the Jacobi symbol
func kroneckerSymbol(_ m: BInt) -> Int
Kronecker symbol - BInt version. If m
is positive and odd, this is also the Jacobi symbol
func lcm(_ x: BInt) -> BInt
Least common multiple - BInt version
func lcm(_ x: Int) -> BInt
Least common multiple - Int version
func mod(_ x: BInt) -> BInt
Modulus - BInt version
func mod(_ x: Int) -> Int
Modulus - Int version
func modInverse(_ m: BInt) -> BInt
Inverse modulus - BInt version
func modInverse(_ m: Int) -> Int
Inverse modulus - Int version
mutating func negate()
Negates self
func nextPrime(_ p: Int = 30) -> BInt
The next probable prime greater than self
func quotientAndRemainder(dividingBy x: BInt) -> (quotient: BInt, remainder: BInt)
Division
func quotientAndRemainder(dividingBy x: Int) -> (quotient: BInt, remainder: Int)
Division
func quotientAndRemainder(dividingBy x: BInt, _ quotient: inout BInt, _ remainder: inout BInt)
Division
func quotientAndRemainder(dividingBy x: Int, _ quotient: inout BInt, _ remainder: inout Int)
Division
func quotientExact(dividingBy x: BInt) -> BInt
Exact division - that is, the remainder of the division is known to be 0
func randomFrom(_ x: BInt) -> BInt
Random value
func randomLessThan() -> BInt
Random value
func randomTo(_ x: BInt) -> BInt
Random value
func root(_ n: Int) -> BInt
n’th root
func rootRemainder(_ n: Int) -> (root: BInt, rem: BInt)
n’th root and remainder
mutating func setBit(_ n: Int)
Set a specified bit - a no-op if bit number < 0
func sqrt() -> BInt
Square root of a non-negative number
func sqrtMod(_ p: BInt) -> BInt?
Square root modulo a prime number - BInt version
func sqrtMod(_ p: Int) -> Int?
Square root modulo a prime number - Int version
func sqrtRemainder() -> (root: BInt, rem: BInt)
Square root and remainder of a non-negative number
func testBit(_ n: Int) -> Bool
Test a specified bit - false
if bit number < 0