# manual-midpoint

Prefer midpoint operations that cannot overflow intermediate arithmetic

Dividing the sum of two numeric values computes the sum before reducing it and may overflow.
Instead, you SHOULD call `.midpoint()` on one operand.

Floating-point midpoint rounding can differ from the expanded arithmetic.

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

## Reported

```ds title="main.ds"
function middle(left: uint32, right: uint32): uint32 {
    return (left + right) / 2;
}
```

## Accepted

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

## Prior art

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

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