A floating-point value is compared with == or != to a fractional literal, which rounding rarely matches exactly
What it finds
Most decimal fractions have no exact binary form: 0.1 + 0.2 == 0.3 is false. Comparing a computed double with a fractional literal therefore depends on rounding. A comparison within a tolerance, or decimal for amounts, gives stable results. Comparisons with whole numbers, which are exact, are left alone.
From the rule's source, floating_point_equality.rs.
class Physics{ bool AtRest(double speed) => speed == 0.1;tx0 reports: speed == 0.1 compares a floating-point value exactly bool Zero(double speed) => speed == 0.0;} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:floating-point-equality" = "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/csharp:floating-point-equality] reason="..."tx0 explain tx0/csharp:floating-point-equality shows the same in the terminal. Found a false positive? Report it.