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

# max

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

## Edition 0.1

```una
pub max(a: Int, b: Int) -> Int
  ensures result >= a and result >= b and (result == a or result == b)
```

The larger of `a` and `b`; in edition 0.2 and later, of any type with `Ord` (`spec/14 §1`, `spec/20 §6`).

## Edition 0.2 and later

```una
pub max[T: Ord](a: T, b: T) -> T
  ensures result >= a and result >= b and (result == a or result == b)
```

The larger of `a` and `b`; in edition 0.2 and later, of any type with `Ord` (`spec/14 §1`, `spec/20 §6`).

In editions 0.2, 0.3, 0.4, 0.5. In edition 0.1: `max(a: Int, b: Int) -> Int`\: integers only.

## Parameters

- `a`: a value
- `b`: another value of the same type

## Returns

`T`: the larger of `a` and `b`\: `result >= a`\, `result >= b`\, and it is one of them.

## See also

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

## Example

`src/shop.una`

```una
module shop

--- How many units to reorder, never fewer than none, and the last of two names in the order of
--- their scalar values.
pub main() -> Unit
  uses @console: Console[print]
=
  let reorder = max(0, b: 10 - 14)
  @console.print("reorder {reorder}")
  let last = max("Desk lamp", b: "Chair")
  @console.print(last)
```

`una run .` prints:

```text
reorder 0
Desk lamp
```

## Specification

- [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1)
- [`spec/20 §6`](https://una-lang.org/en/docs/spec/20-constraints-on-generics/#s6)

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).
