Aller au contenu

Incorrect NaN test (CA2242)

Ce contenu n’est pas encore disponible dans votre langue.

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;