RS.CLIPPY.WHILE_FLOAT

While loops comparing floating point values

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: while_float. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for while loops comparing floating point values.

Why is this bad?

If you increment floating point values, errors can compound, so, use integers instead if possible.

Known problems

The lint will catch all while loops comparing floating point values without regarding the increment.

Example

let mut x = 0.0;
while x < 42.0 {
    x += 1.0;
}

Use instead:

let mut x = 0;
while x < 42 {
    x += 1;
}