Ir al contenido

Incorrect NaN test (CA2242)

Esta página aún no está disponible en tu idioma.

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;