A floating-point variable is changed with ++ or --
What it finds
x++ on a float or double reads like counting, but floating-point numbers lose whole steps once they are large: from 2^24 on, f++ on a float leaves it unchanged. Counting belongs in an integer type; a floating-point value is better changed with an explicit += 1.0 that shows what it is.
From the rule's source, float_counter.rs.
class Counter { void count() { float f = 0; f++;tx0 reports: ++ is applied to a floating-point value double d = 1.5; --d;tx0 reports: -- is applied to a floating-point value int i = 0; i++; }} 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:
[rules]
"tx0/java:float-increment" = "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/java:float-increment] reason="..."tx0 explain tx0/java:float-increment shows the same in the terminal. Found a false positive? Report it.