# no-floating-point-equality

Disallow exact equality comparisons between floating-point values

Floating-point arithmetic rounds intermediate results, so mathematically equivalent calculations can produce different representations.
Instead, you SHOULD compare an absolute or relative error with a tolerance chosen for the value's scale and domain.

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

## Reported

```ds title="main.ds"
function same(left: float64, right: float64): boolean {
    return left === right;
}
```

## Accepted

```ds title="main.ds"
function same(left: float64, right: float64): boolean {
    return (left - right).abs() < 0.001;
}
```

## Prior art

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

[language/linter/src/rules/correctness/no_floating_point_equality.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/correctness/no_floating_point_equality.rs#L6)
