Operator: -

operator - { associativity left precedence }

Declarations

func -(_: Double, rhs: Double)

Subtracts one value from another and produces their difference, rounded to a representable value.

The subtraction operator (-) calculates the difference of its two arguments. For example:

let x = 7.5
let y = x - 2.25
// y == 5.25

The - operator implements the subtraction operation defined by the IEEE 754 specification.

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Double, rhs: Double) -> Double
func -(_: Float, rhs: Float)

Subtracts one value from another and produces their difference, rounded to a representable value.

The subtraction operator (-) calculates the difference of its two arguments. For example:

let x = 7.5
let y = x - 2.25
// y == 5.25

The - operator implements the subtraction operation defined by the IEEE 754 specification.

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Float, rhs: Float) -> Float
func -(_: Float80, rhs: Float80)

Subtracts one value from another and produces their difference, rounded to a representable value.

The subtraction operator (-) calculates the difference of its two arguments. For example:

let x = 7.5
let y = x - 2.25
// y == 5.25

The - operator implements the subtraction operation defined by the IEEE 754 specification.

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Float80, rhs: Float80) -> Float80
func -(_: Int, rhs: Int)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Int, rhs: Int) -> Int
func -(_: Int8, rhs: Int8)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Int8, rhs: Int8) -> Int8
func -(_: Int16, rhs: Int16)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Int16, rhs: Int16) -> Int16
func -(_: Int32, rhs: Int32)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: Int32, rhs: Int32) -> Int32
func -(_: Int64, rhs: Int64)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference, rounded to a representable value.

The subtraction operator (-) calculates the difference of its two arguments. For example:

let x = 7.5
let y = x - 2.25
// y == 5.25

The - operator implements the subtraction operation defined by the IEEE 754 specification.

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

BinaryFloatingPoint, Strideable
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference, rounded to a representable value.

The subtraction operator (-) calculates the difference of its two arguments. For example:

let x = 7.5
let y = x - 2.25
// y == 5.25

The - operator implements the subtraction operation defined by the IEEE 754 specification.

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

BinaryFloatingPoint, Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: Self, rhs: Self.Stride)

Declaration

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

Declared In

Strideable
func -(_: Self, rhs: Self.Stride)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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

Declared In

FixedWidthInteger
func -(_: UInt, rhs: UInt)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: UInt, rhs: UInt) -> UInt
func -(_: UInt8, rhs: UInt8)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: UInt8, rhs: UInt8) -> UInt8
func -(_: UInt16, rhs: UInt16)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: UInt16, rhs: UInt16) -> UInt16
func -(_: UInt32, rhs: UInt32)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

func -(lhs: UInt32, rhs: UInt32) -> UInt32
func -(_: UInt64, rhs: UInt64)

Subtracts one value from another and produces their difference.

The subtraction operator (-) calculates the difference of its two arguments. For example:

8 - 3                   // 5
-10 - 5                 // -15
100 - -5                // 105
10.5 - 100.0            // -89.5

You cannot use - with arguments of different types. To subtract values of different types, convert one of the values to the other value's type.

let x: UInt8 = 21
let y: UInt = 1000000
y - UInt(x)             // 999979

The difference of the two arguments must be representable in the arguments' type. In the following example, the result of 21 - 50 is less than zero, the minimum representable UInt8 value:

x - 50                  // Overflow error

Note: Overflow checking is not performed in -Ounchecked builds.

If you want to opt out of overflow checking and ignore any overflow, use the overflow subtraction operator (&-).

x &- 50                // 227

Parameters: lhs: A numeric value. rhs: The value to subtract from lhs.

Declaration

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