Multiplies two values and stores the result in the left-hand-side variable, wrapping any overflow.
SDK
- Xcode 10.0+
Framework
- Swift Standard Library
Declaration
Parameters
lhsThe first value to multiply.
rhsThe second value to multiply.
Discussion
The masking multiplication assignment operator (&*=) silently wraps any overflow that occurs during the operation. In the following example, the product of 10 and 50 is greater than the maximum representable Int8 value, so the result is the partial value after discarding the overflowing bits.
var x: Int8 = 10
x &*= 5
// x == 50
var y: Int8 = 10
y &*= 50
// y == -12 (after overflow)
For more about arithmetic with overflow operators, see Overflow Operators in The Swift Programming Language.