---
title: "subtract(_:ordering:)"
framework: synchronization
role: symbol
role_heading: Instance Method
path: "synchronization/atomic/subtract(_:ordering:)-pqxe"
---

# subtract(_:ordering:)

Perform an atomic subtract operation and return the old and new value, applying the specified memory ordering.

## Declaration

```swift
@discardableResult func subtract(_ operand: UInt, ordering: AtomicUpdateOrdering) -> (oldValue: UInt, newValue: UInt)
```

## Parameters

- `operand`: An integer value.
- `ordering`: The memory ordering to apply on this operation.

## Return Value

Return Value A tuple containing the original value before the operation and the new value after the operation.

## Discussion

Discussion note: This operation checks for overflow at runtime and will trap if an overflow does occur. In -Ounchecked builds, overflow checking is not performed. The need to check for overflow means that this operation is typically compiled into a compare-exchange loop. For use cases that require a direct atomic subtraction, see the wrappingSubtract operation: it avoids the loop, but in exchange it allows silent wraps on overflow.
