Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V3076. Comparison with 'double.NaN'...
menu mobile close menu
Analyzing projects
Additional information
toggle menu Contents

V3076. Comparison with 'double.NaN' is meaningless. Use 'double.IsNaN()' method instead.

Mar 04 2016

The analyzer detected that a variable of type float or double is compared with a float.NaN or double.NaN value. As stated in the documentation, if two double.NaN values are tested for equality by using the == operator, the result is false. So, no matter what value of type double is compared with double.NaN, the result is always false.

Consider the following example:

void Func(double d) {
  if (d == double.NaN) {
    ....
  }
}

It's incorrect to test the value for NaN using operators == and !=. Instead, method float.IsNaN() or double.IsNaN() should be used. The fixed version of the code:

void Func(double d) {
  if (double.IsNaN(d)) {
    ....
  }
}

This diagnostic rule is classified as:

You can look at examples of errors detected by the V3076 diagnostic.