A type that can represent both positive and negative values.


protocol SignedNumeric


The SignedNumeric protocol extends the operations defined by the Numeric protocol to include a value’s additive inverse.

Conforming to the SignedNumeric Protocol

Because the SignedNumeric protocol provides default implementations of both of its required methods, you don’t need to do anything beyond declaring conformance to the protocol and ensuring that the values of your type support negation. To customize your type’s implementation, provide your own mutating negate() method.

When the additive inverse of a value is unrepresentable in a conforming type, the operation should either trap or return an exceptional value. For example, using the negation operator (prefix -) with Int.min results in a runtime error.

let x = Int.min
let y = -x
// Overflow error


Instance Methods

func negate()

Replaces this value with its additive inverse.

Required. Default implementation provided.

Operator Functions

static func - (Self) -> Self

Returns the additive inverse of the specified value.

Required. Default implementation provided.

See Also

Basic Arithmetic

protocol AdditiveArithmetic

A type with values that support addition and subtraction.

protocol Numeric

A type with values that support multiplication.

protocol Strideable

A type representing continuous, one-dimensional values that can be offset and measured.