An integer division is stored in a floating variable, after its fraction is already lost

tx0/cpp:integer-division-to-floatingrecommendedwarningreliability/arithmeticdepth fastbug, cwe-682

What it finds

double ratio = done / total; with integer done and total: the division is done in integers and the fraction is gone before the value becomes a double. Converting one operand first, (double)done / total, keeps it.

Both operands must be integer literals or names the file declares with an integer type, and the target a variable the file declares as float or double.

From the rule's source, integer_division_to_floating.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:integer-division-to-floating" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/cpp:integer-division-to-floating] reason="..."

tx0 explain tx0/cpp:integer-division-to-floating shows the same in the terminal. Found a false positive? Report it.