# manual-euclidean-remainder

Prefer remainderEuclidean over its manual double-remainder form

Applying remainder twice around an added positive divisor manually normalizes a negative remainder.
Instead, you SHOULD call `.remainderEuclidean()` on the dividend.

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

## Reported

```ds title="main.ds"
function wrap(value: int32): int32 {
    return ((value % 4) + 4) % 4;
}
```

## Accepted

```ds title="main.ds"
function wrap(value: int32): int32 {
    return value.remainderEuclidean(4);
}
```

## Prior art

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

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