Structures

The following structures are available globally.

  • An arbitary precision unsigned integer type, also known as a “big integer”.

    Operations on big integers never overflow, but they may take a long time to execute. The amount of memory (and address space) available is the only constraint to the magnitude of these numbers.

    This particular big integer type uses base-2^64 digits to represent integers; you can think of it as a wrapper around Array<UInt64>. (In fact, BigUInt only uses an array if there are more than two digits.)

    See more

    Declaration

    Swift

    public struct BigUInt : UnsignedInteger
    extension BigUInt: Codable
    extension BigUInt: Comparable
    extension BigUInt: Hashable
    extension BigUInt: ExpressibleByIntegerLiteral
    extension BigUInt: Strideable
    extension BigUInt: ExpressibleByStringLiteral
    extension BigUInt: CustomStringConvertible
    extension BigUInt: CustomPlaygroundDisplayConvertible

BigInt

  • An arbitary precision signed integer type, also known as a “big integer”.

    Operations on big integers never overflow, but they might take a long time to execute. The amount of memory (and address space) available is the only constraint to the magnitude of these numbers.

    This particular big integer type uses base-2^64 digits to represent integers.

    BigInt is essentially a tiny wrapper that extends BigUInt with a sign bit and provides signed integer operations. Both the underlying absolute value and the negative/positive flag are available as read-write properties.

    Not all algorithms of BigUInt are available for BigInt values; for example, there is no square root or primality test for signed integers. When you need to call one of these, just extract the absolute value:

    BigInt(255).magnitude.isPrime()   // Returns false
    
    See more

    Declaration

    Swift

    public struct BigInt : SignedInteger
    extension BigInt: Codable
    extension BigInt: Comparable
    extension BigInt: Hashable
    extension BigInt: ExpressibleByIntegerLiteral
    extension BigInt: Strideable
    extension BigInt: ExpressibleByStringLiteral
    extension BigInt: CustomStringConvertible
    extension BigInt: CustomPlaygroundDisplayConvertible