_Integer

protocol _Integer

This protocol is an implementation detail of Integer; do not use it directly.

Inheritance BitwiseOperations, Comparable, CustomStringConvertible, Equatable, ExpressibleByIntegerLiteral, Hashable, IntegerArithmetic, _Incrementable, _IntegerArithmetic View Protocol Hierarchy →
Associated Types
IntegerLiteralType
Import import Swift

Initializers

init(integerLiteral:) Required

Create an instance initialized to value.

Declaration

init(integerLiteral value: Self.IntegerLiteralType)

Declared In

ExpressibleByIntegerLiteral

Static Variables

static var allZeros: Self Required

The empty bitset.

The allZeros static property is the identity element for bitwise OR and XOR operations and the fixed point for bitwise AND operations. For example:

let x: UInt8 = 5        // 0b00000101

// Identity
x | .allZeros           // 0b00000101
x ^ .allZeros           // 0b00000101

// Fixed point
x & .allZeros           // 0b00000000

Declaration

static var allZeros: Self { get }

Declared In

BitwiseOperations

Instance Variables

var description: String Required

A textual representation of this instance.

Instead of accessing this property directly, convert an instance of any type to a string by using the String(describing:) initializer. For example:

struct Point: CustomStringConvertible {
    let x: Int, y: Int

    var description: String {
        return "(\(x), \(y))"
    }
}

let p = Point(x: 21, y: 30)
let s = String(describing: p)
print(s)
// Prints "(21, 30)"

The conversion of p to a string in the assignment to s uses the Point type's description property.

Declaration

var description: String { get }

Declared In

CustomStringConvertible
var hashValue: Int Required

The hash value.

Hash values are not guaranteed to be equal across different executions of your program. Do not save hash values to use during a future execution.

Declaration

var hashValue: Int { get }

Declared In

Hashable

Static Methods

static func addWithOverflow(_:_:) Required

Adds lhs and rhs, returning the result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func addWithOverflow(_ lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)

Declared In

_IntegerArithmetic
static func divideWithOverflow(_:_:) Required

Divides lhs and rhs, returning the result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func divideWithOverflow(_ lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)

Declared In

_IntegerArithmetic
static func multiplyWithOverflow(_:_:) Required

Multiplies lhs and rhs, returning the result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func multiplyWithOverflow(_ lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)

Declared In

_IntegerArithmetic
static func remainderWithOverflow(_:_:) Required

Divides lhs and rhs, returning the remainder and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func remainderWithOverflow(_ lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)

Declared In

_IntegerArithmetic
static func subtractWithOverflow(_:_:) Required

Subtracts lhs and rhs, returning the result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func subtractWithOverflow(_ lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)

Declared In

_IntegerArithmetic

Instance Methods

func %(_:rhs:) Required

Divides lhs and rhs, returning the remainder and trapping in case of arithmetic overflow (except in -Ounchecked builds).

Declaration

func %(lhs: Self, rhs: Self) -> Self

Declared In

IntegerArithmetic
func &(_:rhs:) Required

Returns the intersection of bits set in the two arguments.

The bitwise AND operator (&) returns a value that has each bit set to 1 where both of its arguments had that bit set to 1. This is equivalent to the intersection of two sets. For example:

let x: UInt8 = 5        // 0b00000101
let y: UInt8 = 14       // 0b00001110
let z = x & y           // 0b00000100

Performing a bitwise AND operation with a value and allZeros always returns allZeros.

print(x & .allZeros)    // 0b00000000
// Prints "0"

Complexity: O(1).

Declaration

func &(lhs: Self, rhs: Self) -> Self

Declared In

BitwiseOperations
func *(_:rhs:) Required

Multiplies lhs and rhs, returning the result and trapping in case of arithmetic overflow (except in -Ounchecked builds).

Declaration

func *(lhs: Self, rhs: Self) -> Self

Declared In

IntegerArithmetic
func +(_:rhs:) Required

Adds lhs and rhs, returning the result and trapping in case of arithmetic overflow (except in -Ounchecked builds).

Declaration

func +(lhs: Self, rhs: Self) -> Self

Declared In

IntegerArithmetic
func /(_:rhs:) Required

Divides lhs and rhs, returning the result and trapping in case of arithmetic overflow (except in -Ounchecked builds).

Declaration

func /(lhs: Self, rhs: Self) -> Self

Declared In

IntegerArithmetic
func <(_:rhs:) Required

Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.

This function is the only requirement of the Comparable protocol. The remainder of the relational operator functions are implemented by the standard library for any type that conforms to Comparable.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func <(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func <=(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func <=(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func ==(_:rhs:) Required

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Self, rhs: Self) -> Bool

Declared In

Equatable
func >(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func >(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func >=(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func >=(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func ^(_:rhs:) Required

Returns the bits that are set in exactly one of the two arguments.

The bitwise XOR operator (^), or exclusive OR operator, returns a value that has each bit set to 1 where one or the other but not both of its operators has that bit set to 1. This is equivalent to the symmetric difference of two sets. For example:

let x: UInt8 = 5        // 0b00000101
let y: UInt8 = 14       // 0b00001110
let z = x ^ y           // 0b00001011

Performing a bitwise XOR with a value and allZeros always returns the same value:

print(x ^ .allZeros)    // 0b00000101
// Prints "5"

Complexity: O(1).

Declaration

func ^(lhs: Self, rhs: Self) -> Self

Declared In

BitwiseOperations
func |(_:rhs:) Required

Returns the union of bits set in the two arguments.

The bitwise OR operator (|) returns a value that has each bit set to 1 where one or both of its arguments had that bit set to 1. For example:

let x: UInt8 = 5        // 0b00000101
let y: UInt8 = 14       // 0b00001110
let z = x | y           // 0b00001111

Performing a bitwise OR operation with a value and allZeros always returns the same value.

print(x | .allZeros)    // 0b00000101
// Prints "5"

Complexity: O(1).

Declaration

func |(lhs: Self, rhs: Self) -> Self

Declared In

BitwiseOperations
prefix func ~(_:) Required

Returns the inverse of the bits set in the argument.

The bitwise NOT operator (~) is a prefix operator that returns a value in which all the bits of its argument are flipped: Bits that are 1 in the argument are 0 in the result, and bits that are 0 in the argument are 1 in the result. This is equivalent to the inverse of a set. For example:

let x: UInt8 = 5        // 0b00000101
let notX = ~x           // 0b11111010

Performing a bitwise NOT operation on allZeros returns a value with every bit set to 1.

let allOnes = ~UInt8.allZeros   // 0b11111111

Complexity: O(1).

Declaration

prefix func ~(x: Self) -> Self

Declared In

BitwiseOperations
func -(_:rhs:) Required

Subtracts lhs and rhs, returning the result and trapping in case of arithmetic overflow (except in -Ounchecked builds).

Declaration

func -(lhs: Self, rhs: Self) -> Self

Declared In

IntegerArithmetic
func toIntMax() Required

Explicitly convert to IntMax, trapping on overflow (except in -Ounchecked builds).

Declaration

func toIntMax() -> IntMax

Declared In

IntegerArithmetic