Zum Inhalt springen

Incorrect NaN test (CA2242)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key dotnet.codequality.nan-comparison · Severity error · Category codequality

Microsoft analyzer CA2242. Flags a comparison with double.NaN or float.NaN. NaN is never equal to anything, itself included, so the test is always false; double.IsNaN is the check.

if (ratio == double.NaN)
return 0;
if (double.IsNaN(ratio))
return 0;