Instance Method


Replaces this value with its additive inverse.


mutating func negate()


The following example uses the negate() method to negate the value of an integer x:

var x = 21
// 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
// Overflow error

See Also

Performing Calculations

Integer Operators

Perform arithmetic and bitwise operations or compare values.

func quotientAndRemainder(dividingBy: Int) -> (quotient: Int, remainder: Int)

Returns the quotient and remainder of this value divided by the given value.

func isMultiple(of: Int) -> Bool

Returns true if this value is a multiple of the given value, and false otherwise.