# manual-saturating-arithmetic

Prefer saturating arithmetic over equivalent manual bounds logic

Falling back from checked unsigned arithmetic to the matching integer bound manually implements saturation.
Instead, you SHOULD call the corresponding saturating arithmetic method.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function add(left: uint32, right: uint32): uint32 {
    return left.checkedAdd(right) ?? uint32.maximum();
}
```

## Accepted

```ds title="main.ds"
function add(left: uint32, right: uint32): uint32 {
    return left.saturatingAdd(right);
}
```

## Prior art

- [Clippy · manual_saturating_arithmetic](https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic)

[language/linter/src/rules/style/manual_saturating_arithmetic.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/manual_saturating_arithmetic.rs#L8)
