Operator

&-=(_:_:)

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

Declaration

static func &-= (lhs: inout Int, rhs: Int)

Parameters

lhs

A numeric value.

rhs

The value to subtract from lhs.

Discussion

The masking subtraction assignment operator (&-=) silently wraps any overflow that occurs during the operation. In the following example, the difference of 10 and 21 is less than zero, the minimum representable UInt value, so the result is the result is the partial value after discarding the overflowing bits.

var x: Int8 = 21
x &-= 10
// x == 11
var y: UInt8 = 10
y &-= 21
// y == 245 (after overflow)

For more about arithmetic with overflow operators, see Overflow Operators in The Swift Programming Language.

See Also

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)

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