Integer Operators

Perform arithmetic and bitwise operations or compare values.

Topics

Arithmetic

static func + (Int, Int) -> Int

Adds two values and produces their sum.

static func - (Int, Int) -> Int

Subtracts one value from another and produces their difference.

static func * (Int, Int) -> Int

Multiplies two values and produces their product.

static func / (Int, Int) -> Int

Returns the quotient of dividing the first value by the second.

static func % (Int, Int) -> Int

Returns the remainder of dividing the first value by the second.

Arithmetic with Assignment

static func += (inout Int, Int)

Adds two values and stores the result in the left-hand-side variable.

static func *= (inout Int, Int)

Multiplies two values and stores the result in the left-hand-side variable.

static func /= (inout Int, Int)

Divides the first value by the second and stores the quotient in the left-hand-side variable.

static func %= (inout Int, Int)

Divides the first value by the second and stores the remainder in the left-hand-side variable.

Masked Arithmetic

static func &+ (Int, Int) -> Int

Returns the sum of the two given values, wrapping the result in case of any overflow.

static func &- (Int, Int) -> Int

Returns the difference of the two given values, wrapping the result in case of any overflow.

static func &* (Int, Int) -> Int

Returns the product of the two given values, wrapping the result in case of any overflow.

static func &+= (inout Int, Int)

Adds two values and stores the result in the left-hand-side variable, wrapping any overflow.

static func &-= (inout Int, Int)

Subtracts the second value from the first and stores the difference in the left-hand-side variable, wrapping any overflow.

static func &*= (inout Int, Int)

Multiplies two values and stores the result in the left-hand-side variable, wrapping any overflow.

Bitwise Operations

static func & (Int, Int) -> Int

Returns the result of performing a bitwise AND operation on the two given values.

static func & (Int, Int) -> Int

Returns the result of performing a bitwise AND operation on the two given values.

static func &= (inout Int, Int)

Stores the result of performing a bitwise AND operation on the two given values in the left-hand-side variable.

static func | (Int, Int) -> Int

Returns the result of performing a bitwise OR operation on the two given values.

static func | (Int, Int) -> Int

Returns the result of performing a bitwise OR operation on the two given values.

static func |= (inout Int, Int)

Stores the result of performing a bitwise OR operation on the two given values in the left-hand-side variable.

static func ^ (Int, Int) -> Int

Returns the result of performing a bitwise XOR operation on the two given values.

static func ^ (Int, Int) -> Int

Returns the result of performing a bitwise XOR operation on the two given values.

static func ^= (inout Int, Int)

Stores the result of performing a bitwise XOR operation on the two given values in the left-hand-side variable.

static func ~ (Int) -> Int

Returns the inverse of the bits set in the argument.

Bit Shift

static func << <Other>(Int, Other) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left.

static func << <RHS>(Int, RHS) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left.

static func <<= <Other>(inout Int, Other)

Stores the result of shifting a value’s binary representation the specified number of digits to the left in the left-hand-side variable.

static func >> <Other>(Int, Other) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right.

static func >> <RHS>(Int, RHS) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right.

static func >>= <Other>(inout Int, Other)

Stores the result of shifting a value’s binary representation the specified number of digits to the right in the left-hand-side variable.

static func &<< (Int, Int) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.

static func &<< (Int, Int) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.

static func &<< <Other>(Int, Other) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.

static func &<<= (inout Int, Int)

Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.

static func &<<= <Other>(inout Int, Other)

Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.

static func &>> (Int, Int) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width.

static func &>> (Int, Int) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width.

static func &>> <Other>(Int, Other) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width.

static func &>>= (inout Int, Int)

Calculates the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.

static func &>>= <Other>(inout Int, Other)

Calculates the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.

Negation

static func - (Int) -> Int

Returns the additive inverse of the specified value.

static func + (Int) -> Int

Returns the given number unchanged.

Comparison

static func == (Int, Int) -> Bool

Returns a Boolean value indicating whether two values are equal.

static func == (Int, Int) -> Bool

Returns a Boolean value indicating whether two values are equal.

static func == <Other>(Int, Other) -> Bool

Returns a Boolean value indicating whether the two given values are equal.

static func != (Int, Int) -> Bool

Returns a Boolean value indicating whether two values are not equal.

static func != <Other>(Int, Other) -> Bool

Returns a Boolean value indicating whether the two given values are not equal.

static func < (Int, Int) -> Bool

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

static func < (Int, Int) -> Bool

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

static func < <Other>(Int, Other) -> Bool

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

static func <= (Int, Int) -> Bool

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

static func <= (Int, Int) -> Bool

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

static func <= (Int, Int) -> Bool

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

static func <= <Other>(Int, Other) -> Bool

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

static func > (Int, Int) -> Bool

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

static func > (Int, Int) -> Bool

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

static func > (Int, Int) -> Bool

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

static func > <Other>(Int, Other) -> Bool

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

static func >= (Int, Int) -> Bool

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

static func >= (Int, Int) -> Bool

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

static func >= (Int, Int) -> Bool

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

static func >= <Other>(Int, Other) -> Bool

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

Range Expressions

static func ..< (Int, Int) -> Range<Int>

Returns a half-open range that contains its lower bound but not its upper bound.

static func ... (Int, Int) -> ClosedRange<Int>

Returns a closed range that contains both of its bounds.

static func ... (Int) -> PartialRangeFrom<Int>

Returns a partial range extending upward from a lower bound.

static func ..< (Int) -> PartialRangeUpTo<Int>

Returns a partial range up to, but not including, its upper bound.

static func ... (Int) -> PartialRangeThrough<Int>

Returns a partial range up to, and including, its upper bound.

Deprecated

static func -= (inout Int, Int)

Subtracts the second value from the first and stores the difference in the left-hand-side variable.

See Also

Performing Calculations

func negate()

Replaces this value with its additive inverse.

func quotientAndRemainder(dividingBy: Int) -> (quotient: Int, remainder: Int)

Returns the quotient and remainder of this value divided by the given value.

func isMultiple(of: Int) -> Bool

Returns true if this value is a multiple of the given value, and false otherwise.