A number is compared with math.NaN(), which gives the same result for every number
What it finds
x == math.NaN(): NaN is not equal to anything, itself included, and every ordered comparison with it is false, so the comparison has the same result whatever x is. math.IsNaN(x) tells whether a number is NaN.
Reported are comparisons with ==, !=, <, <=, > or >= where one operand is a call of NaN of the package math, resolved through the imports.
From the rule's source, nan_comparison.rs.
package p import "math" func f(x float64) bool { if x == math.NaN() {tx0 reports: a comparison with NaN is always false return true } if math.NaN() != x {tx0 reports: a comparison with NaN is always true return false } return math.IsNaN(x) || x == math.Inf(1)} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:nan-comparison" = "off"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/go:nan-comparison] reason="..."tx0 explain tx0/go:nan-comparison shows the same in the terminal. Found a false positive? Report it.