# float-equality-without-abs

Require an absolute difference in `Number.EPSILON` comparisons

`left - right < Number.EPSILON` accepts every negative difference, including values that are arbitrarily far apart.
Instead, you SHOULD compare the absolute difference: `(left - right).abs() < Number.EPSILON`.

The absolute value is unnecessary only when `left >= right` is a proven invariant.

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

## Reported

```ds title="main.ds"
function approximatelyEqual(left: float64, right: float64): boolean {
    return left - right < Number.EPSILON;
}
```

## Accepted

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

## Prior art

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

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