Protocolswift 6.0.1Swift
SignedNumeric
A numeric type with a negation operation.
protocol SignedNumeric : Numeric
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
Supertypes
protocol AdditiveArithmetic
A type with values that support addition and subtraction.
protocol Equatable
A type that can be compared for value equality.
protocol ExpressibleByIntegerLiteral
A type that can be initialized with an integer literal.
protocol Numeric
A type with values that support multiplication.
Requirements
Type members
static func - (operand: Self
) -> Self Returns the additive inverse of the specified value.
Instance members
func negate(
) Replaces this value with its additive inverse.
Citizens in Swift
Type members
static func - (operand: Self
) -> Self Returns the additive inverse of the specified value.
Instance members
func negate(
) Replaces this value with its additive inverse.
Subtypes
protocol BinaryFloatingPoint
A radix-2 (binary) floating-point type.
protocol FloatingPoint
A floating-point numeric type.
protocol SignedInteger
An integer type that can represent both positive and negative values.
Extension in RealModule
Subtypes
protocol AlgebraicField
A type modeling an algebraic field. Refines the
SignedNumeric
protocol, adding division.protocol Real
A type that models the real numbers.