Operator 演算子

&+=(_:_:)

Adds two values and stores the result in the left-hand-side variable, wrapping any overflow. 2つの値を加算して結果を左手側の変数に格納します、あらゆるオーバーフローをラップします。

Declaration 宣言

static func &+= (lhs: inout UInt8, rhs: UInt8)

Parameters パラメータ

lhs

The first value to add. 加算する第1の値。

rhs

The second value to add. 加算する第2の値。

Discussion 解説

The masking addition assignment operator (&+=) silently wraps any overflow that occurs during the operation. 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. マスク加算代入演算子(&+=)は、演算の間に起こるあらゆるオーバーフローを黙ってラップします。以下の例において、100121の合計は、最大限表現可能なInt8値より大きいです、それで結果はオーバーフローするビットを廃棄後の部分的な値です。


var x: Int8 = 10
x &+= 21
// x == 31
var y: Int8 = 100
y &+= 121
// y == -35 (after overflow)

For more about arithmetic with overflow operators, see Overflow Operators in The Swift Programming Language. オーバーフロー演算子を使う算術についてさらには、オーバーフロー演算子Swiftプログラミング言語で見てください。