SignedNumber

protocol SignedNumber

Instances of conforming types can be subtracted, arithmetically negated, and initialized from 0.

Axioms:

  • x - 0 == x
  • -x == 0 - x
  • -(-x) == x
Inheritance Comparable, Equatable, ExpressibleByIntegerLiteral View Protocol Hierarchy →
Associated Types
IntegerLiteralType

A type that represents an integer literal.

The standard library integer and floating-point types are all valid types for IntegerLiteralType.

Import import Swift

Initializers

init(integerLiteral:)

Creates an instance initialized to the specified integer value.

Do not call this initializer directly. Instead, initialize a variable or constant using an integer literal. For example:

let x = 23

In this example, the assignment to the x constant calls this integer literal initializer behind the scenes.

value: The value to create.

Declaration

init(integerLiteral value: Self.IntegerLiteralType)

Declared In

ExpressibleByIntegerLiteral

Instance Methods

func <(_:rhs:) Required

Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.

This function is the only requirement of the Comparable protocol. The remainder of the relational operator functions are implemented by the standard library for any type that conforms to Comparable.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func <(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func <=(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func <=(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func ==(_:rhs:) Required

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Self, rhs: Self) -> Bool

Declared In

Equatable
func >(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func >(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func >=(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func >=(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
prefix func -(_:) Required

Returns the result of negating x.

Declaration

prefix func -(x: Self) -> Self
func -(_:rhs:) Required

Returns the difference between lhs and rhs.

Declaration

func -(lhs: Self, rhs: Self) -> Self

Default Implementations

init(integerLiteral:)

Create an instance initialized to value.

Declaration

init(integerLiteral value: Self)

Declared In

ExpressibleByIntegerLiteral