Operator 演算子

-(_:)

Returns the additive inverse of the specified value. 指定された値の加法の逆元を返します。

Declaration 宣言

prefix static func - (operand: Self) -> Self

Return Value 戻り値

The additive inverse of this value. この値の加法の逆元。

Discussion 解説

The negation operator (prefix -) returns the additive inverse of its argument. 負にする演算子(前置-)は、この引数の加法の逆元を返します。


let x = 21
let y = -x
// y == -21

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


let z = -Int8.min
// Overflow error

Default Implementations 省略時実装

SignedNumeric Implementations