FixedWidthInteger

protocol FixedWidthInteger
Inheritance Arithmetic, BinaryInteger, Comparable, CustomStringConvertible, Equatable, ExpressibleByIntegerLiteral View Protocol Hierarchy →
Associated Types
Magnitude : Equatable, ExpressibleByIntegerLiteral
IntegerLiteralType

A type that represents an integer literal.

The standard library integer and floating-point types are all valid types for IntegerLiteralType.

Import import Swift

Initializers

init<T where T : BinaryInteger>(_: T)

Declaration

init<T where T : BinaryInteger>(_ source: T)

Declared In

BinaryInteger
init<T where T : FloatingPoint>(_: T)

Declaration

init<T where T : FloatingPoint>(_ source: T)

Declared In

BinaryInteger
init(clamping:)

Declaration

init<T where T : BinaryInteger>(clamping source: T)

Declared In

BinaryInteger
init(extendingOrTruncating:)

Declaration

init<T where T : BinaryInteger>(extendingOrTruncating source: T)

Declared In

BinaryInteger
init?(exactly:)

Declaration

init?<T where T : FloatingPoint>(exactly source: T)

Declared In

BinaryInteger
init(integerLiteral:)

Creates an instance initialized to the specified integer value.

Do not call this initializer directly. Instead, initialize a variable or constant using an integer literal. For example:

let x = 23

In this example, the assignment to the x constant calls this integer literal initializer behind the scenes.

value: The value to create.

Declaration

init(integerLiteral value: Self.IntegerLiteralType)

Declared In

ExpressibleByIntegerLiteral

Static Variables

static var bitWidth: Int Required

Declaration

static var bitWidth: Int { get }
static var max: Self Required

Declaration

static var max: Self { get }
static var min: Self Required

Declaration

static var min: Self { get }
static var isSigned: Bool Required

Declaration

static var isSigned: Bool { get }

Declared In

BinaryInteger

Instance Variables

var leadingZeros: Int Required

Declaration

var leadingZeros: Int { get }
var popcount: Int

Declaration

var popcount: Int { get }
var magnitude: Self.Magnitude Required

Declaration

var magnitude: Self.Magnitude { get }

Declared In

Arithmetic
var minimumSignedRepresentationBitWidth: Int Required

Declaration

var minimumSignedRepresentationBitWidth: Int { get }

Declared In

BinaryInteger
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

Static Methods

static func doubleWidthDivide(_ lhs: (high: Self,:_:)

Declaration

static func doubleWidthDivide(_ lhs: (high: Self, low: Self.Magnitude), _ rhs: Self) -> (quotient: Self, remainder: Self)
static func doubleWidthMultiply(_:_:) Required

Declaration

static func doubleWidthMultiply(_ lhs: Self, _ rhs: Self) -> (high: Self, low: Self.Magnitude)

Instance Methods

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
mutating func add(_:)

Declaration

mutating func add(_ rhs: Self)

Declared In

Arithmetic
func adding(_:)

Declaration

func adding(_ rhs: Self) -> Self

Declared In

Arithmetic
func addingWithOverflow(_:) Required

Return a pair consisting of self + rhs, truncated to fit if necessary, and a flag indicating whether an arithmetic overflow occurred.

Declaration

func addingWithOverflow(_ rhs: Self) -> (partialValue: Self, overflow: ArithmeticOverflow)
func bitwiseAnd(_:) Required

Declaration

func bitwiseAnd(_ rhs: Self) -> Self
func bitwiseOr(_:) Required

Declaration

func bitwiseOr(_ rhs: Self) -> Self
func bitwiseXor(_:) Required

Declaration

func bitwiseXor(_ rhs: Self) -> Self
mutating func divide(by:)

Declaration

mutating func divide(by rhs: Self)

Declared In

Arithmetic
func divided(by:)

Declaration

func divided(by rhs: Self) -> Self

Declared In

Arithmetic
func dividedWithOverflow(by:) Required

Return a pair consisting of self / rhs, truncated to fit if necessary, and a flag indicating whether an arithmetic overflow occurred.

Precondition: rhs != 0

Declaration

func dividedWithOverflow(by rhs: Self) -> (partialValue: Self, overflow: ArithmeticOverflow)
mutating func formRemainder(dividingBy:)

Declaration

mutating func formRemainder(dividingBy rhs: Self)

Declared In

BinaryInteger
func isEqual(to:) Required

Declaration

func isEqual(to rhs: Self) -> Bool

Declared In

BinaryInteger
func isLess(than:) Required

Declaration

func isLess(than rhs: Self) -> Bool

Declared In

BinaryInteger
func maskingShiftLeft(_:) Required

Declaration

func maskingShiftLeft(_ rhs: Self) -> Self
func maskingShiftRight(_:) Required

Declaration

func maskingShiftRight(_ rhs: Self) -> Self
func multiplied(by:)

Declaration

func multiplied(by rhs: Self) -> Self

Declared In

Arithmetic
func multipliedWithOverflow(by:) Required

Return a pair consisting of self * rhs, truncated to fit if necessary, and a flag indicating whether an arithmetic overflow occurred.

Declaration

func multipliedWithOverflow(by rhs: Self) -> (partialValue: Self, overflow: ArithmeticOverflow)
mutating func multiply(by:)

Declaration

mutating func multiply(by rhs: Self)

Declared In

Arithmetic
func quotientAndRemainder(dividingBy:)

Declaration

func quotientAndRemainder(dividingBy rhs: Self) -> (Self, Self)

Declared In

BinaryInteger
func remainder(dividingBy:)

Declaration

func remainder(dividingBy rhs: Self) -> Self

Declared In

BinaryInteger
func signum()

Returns -1 if the value of self is negative, 1 if it's positive, 0 otherwise.

Declaration

func signum() -> Self

Declared In

BinaryInteger
mutating func subtract(_:)

Declaration

mutating func subtract(_ rhs: Self)

Declared In

Arithmetic
func subtracting(_:)

Declaration

func subtracting(_ rhs: Self) -> Self

Declared In

Arithmetic
func subtractingWithOverflow(_:) Required

Return a pair consisting of self - rhs, truncated to fit if necessary, and a flag indicating whether an arithmetic overflow occurred.

Declaration

func subtractingWithOverflow(_ rhs: Self) -> (partialValue: Self, overflow: ArithmeticOverflow)
func word(at:) Required

Declaration

func word(at n: Int) -> UInt

Declared In

BinaryInteger

Default Implementations

init()

Declaration

init()

Declared In

BinaryInteger , Arithmetic
init(_:)

Declaration

init<T where T : FloatingPoint>(_ source: T)

Declared In

BinaryInteger
init(clamping:)

Declaration

init<Other where Other : BinaryInteger>(clamping source: Other)
init(extendingOrTruncating:)

Declaration

init<T where T : BinaryInteger>(extendingOrTruncating source: T)
init(integerLiteral:)

Create an instance initialized to value.

Declaration

init(integerLiteral value: Self)

Declared In

BinaryInteger , Arithmetic , ExpressibleByIntegerLiteral
init?(exactly:)

Declaration

init?<T where T : FloatingPoint>(exactly source: T)

Declared In

BinaryInteger
var countRepresentedWords: Int

Declaration

var countRepresentedWords: Int { get }

Declared In

BinaryInteger
var popcount: Int

Declaration

var popcount: Int { get }
mutating func add(_:)

Declaration

mutating func add(_ rhs: Self)
func adding(_:)

Declaration

func adding(_ rhs: Self) -> Self

Declared In

BinaryInteger, Arithmetic
mutating func divide(by:)

Declaration

mutating func divide(by rhs: Self)
func divided(by:)

Declaration

func divided(by rhs: Self) -> Self

Declared In

BinaryInteger, Arithmetic
static func doubleWidthDivide(_ lhs: (high: Self,:_:)

Declaration

static func doubleWidthDivide(_ lhs: (high: Self, low: Self.Magnitude), _ rhs: Self) -> (quotient: Self, remainder: Self)
mutating func formRemainder(dividingBy:)

Declaration

mutating func formRemainder(dividingBy other: Self)
func multiplied(by:)

Declaration

func multiplied(by rhs: Self) -> Self

Declared In

BinaryInteger, Arithmetic
mutating func multiply(by:)

Declaration

mutating func multiply(by rhs: Self)
func quotientAndRemainder(dividingBy:)

Declaration

func quotientAndRemainder(dividingBy rhs: Self) -> (Self, Self)

Declared In

BinaryInteger
func remainder(dividingBy:)

Declaration

func remainder(dividingBy rhs: Self) -> Self

Declared In

BinaryInteger
func signum()

Returns -1 if the value of self is negative, 1 if it's positive, 0 otherwise.

Declaration

func signum() -> Self

Declared In

BinaryInteger
mutating func subtract(_:)

Declaration

mutating func subtract(_ rhs: Self)
func subtracting(_:)

Declaration

func subtracting(_ rhs: Self) -> Self

Declared In

BinaryInteger, Arithmetic
func unsafeAdding(_:)

Return self + rhs. If an arithmetic overflow occurs, the behavior is undefined.

Note: use this function to avoid the cost of overflow checking when you are sure that the operation won't overflow.

Declaration

func unsafeAdding(rhs: Self) -> Self
func unsafeDivided(_:)

Return self / rhs. If an arithmetic overflow occurs, the behavior is undefined.

Note: use this function to avoid the cost of overflow checking when you are sure that the operation won't overflow.

Declaration

func unsafeDivided(rhs: Self) -> Self
func unsafeMultiplied(_:)

Return self * rhs. If an arithmetic overflow occurs, the behavior is undefined.

Note: use this function to avoid the cost of overflow checking when you are sure that the operation won't overflow.

Declaration

func unsafeMultiplied(rhs: Self) -> Self
func unsafeSubtracting(_:)

Return self - rhs. If an arithmetic overflow occurs, the behavior is undefined.

Note: use this function to avoid the cost of overflow checking when you are sure that the operation won't overflow.

Declaration

func unsafeSubtracting(rhs: Self) -> Self