Returns the sum of the two given values, wrapping the result in case of any overflow.
SDK
- Xcode 10.0+
Framework
- Swift Standard Library
Declaration
Parameters
lhs
The first value to add.
rhs
The second value to add.
Discussion
The overflow addition operator (&+
) discards any bits that overflow the fixed width of the integer type. In the following example, the sum of 100
and 121
is greater than the maximum representable Int8
value, so the result is the partial value after discarding the overflowing bits.
For more about arithmetic with overflow operators, see Overflow Operators in The Swift Programming Language.