---
title: "abs"
url: https://una-lang.org/en/docs/std/prelude/abs/
release: v0.4.0
edition: "0.1 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/listing.json
---

# abs

A function of the prelude, in scope in every module. Edition 0.1 and later.

```una
pub abs(x: Int) -> Int
  ensures result >= 0 and (result == x or result == -x)
```

The absolute value of `x` (`spec/14 §1`).

## Parameters

- `x`: the number

## Returns

`Int`: the absolute value of `x`\: at least `0`\, and either `x` or `-x`.

## See also

[`Nat`](https://una-lang.org/en/docs/std/prelude/Nat/)

## Example

`src/shop.una`

```una
module shop

--- How far a counted stock is from the book stock, either way.
pub main() -> Unit
  uses @console: Console[print]
=
  let gap = abs(18 - 21)
  @console.print("off by {gap}")
```

`una run .` prints:

```text
off by 3
```

## Specification

- [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1)

Generated from the standard modules of una v0.4.0 ([`docs/std/listing.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/listing.json), which is not part of the specification). The specification governs: [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1).
