<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/abs(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s3absyxxSLRzs13SignedNumericRzlF"
  },
  "title" : "abs(_:)"
}
-->

# abs(_:)

Returns the absolute value of the given number.

```
func abs<T>(_ x: T) -> T where T : Comparable, T : SignedNumeric
```

## Parameters

`x`

A signed number.

## Return Value

The absolute value of `x`.

## Discussion

The absolute value of `x` must be representable in the same type. In
particular, the absolute value of a signed, fixed-width integer type’s
minimum cannot be represented.

```
let x = Int8.min
// x == -128
let y = abs(x)
// Overflow error
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)