# no-float-loop-counter

Disallow float loop counters accumulated by repeated addition

Repeated floating-point addition accumulates rounding error and may skip the intended loop bound.
Instead, you SHOULD count with an integer and derive each floating-point value from that counter.

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

## Reported

```ds title="main.ds"
for (let value: float64 = 0.0; value < 1.0; value += 0.1) {
    // sample the interval
}
```

## Accepted

```ds title="main.ds"
for (let index: int32 = 0; index < 10; index++) {
    const value = (index as float64) / 10.0;
}
```

## Prior art

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

[language/linter/src/rules/correctness/no_float_loop_counter.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/correctness/no_float_loop_counter.rs#L7)
