---
title: "Fixed-width integers"
url: https://una-lang.org/en/docs/guides/fixed-width-integers/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/docs/guide/una-for-agents.md
---

# Fixed-width integers

`Int` stays unbounded. `I8`, `I16`, `I32`, `I64`, `U8`, `U16`, `U32` and `U64` exist where the width matters (`spec/18`).

- A literal takes the fixed-width type its context expects, including inside a constructor or a list (`Some(3)` against `Option[U8]`); otherwise it is an `Int`. A literal that does not fit is U2022.
- Operands of an operator have one integer type; there is no implicit conversion (U2001). Each `+`, `-`, `*`, `/`, `mod` and unary `-` on a fixed-width type, and each narrowing conversion, is an `overflow` obligation: the exact result fits. A refuted one is U5001 with a counterexample.
- Conversions are methods: `to_i8()` to `to_u64()` and `to_int()`. Widening always succeeds; narrowing carries an `overflow` obligation.
- Wrapping, saturating and bit arithmetic exist only by name: `wrapping_add(by: b)`, `saturating_sub(by: b)`, `bit_and(mask: m)`, `shift_right(by: n)` and the others of `spec/18 §5`.
- Clauses (`where`, `requires`, `ensures`) and the bodies of `reflect` predicates compute exactly, with no overflow obligation: `ensures result <= 300` on a `U8` result is proven.

```una
module demo

--- A literal takes the type it is checked against: `Some(3)` here is an `Option[U8]`.
pub default_level() -> Option[U8] = Some(3)

--- The guard on `Int` proves that `a + b` fits a `U8`.
pub add_bytes(a: U8, b: U8) -> U8 = if a.to_int() + b.to_int() <= 255 then a + b else 255

--- Wrapping arithmetic only by name.
pub hash_step(h: U32, byte: U8) -> U32 = h.wrapping_mul(by: 31).wrapping_add(by: byte.to_u32())

--- A `reflect` body computes exactly, with no overflow obligation.
pub predicate reflect large(x: U32) -> Bool = x * 4294967295 > 4294967295
```

```una
-- fails with U5001
module demo

pub add(a: U8, b: U8) -> U8 = a + b
```
