Instance Method インスタンスメソッド

negate()

Replaces this value with its additive inverse. この値をそれの反数と置き換えます。

Declaration 宣言

mutating func negate()

Discussion 議論

The following example uses the negate() method to negate the value of an integer x: 以下の例は、negate()メソッドを使って、整数xの値を否定します:


var x = 21
x.negate()
// x == -21

The resulting value must be representable within the value’s type. In particular, negating a signed, fixed-width integer type’s minimum results in a value that cannot be represented. 結果値は、値の持つ型内で表現可能でなければなりません。とりわけ、符号付き、固定長整数型のもつ最小量を否定することは、表現できない値という結果になります。


var y = Int8.min
y.negate()
// Overflow error

See Also 参照

Managing Stride Properties