A value is compared with NaN using == or !=
What it finds
NaN is not equal to anything, itself included, so x == double.NaN is always false and x != double.NaN always true. double.IsNaN(x) tests what was meant.
From the rule's source, nan_comparison.rs.
class Numbers{ bool Check(double x, float y) { if (x == double.NaN)tx0 reports: comparing with double.NaN is always false { return false; } return y != float.NaN || double.IsNaN(x);tx0 reports: comparing with float.NaN is always true }} 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/csharp: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/csharp:nan-comparison] reason="..."tx0 explain tx0/csharp:nan-comparison shows the same in the terminal. Found a false positive? Report it.