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

V8018. Comparison with 'math.NaN()' is meaningless. Use the 'math.IsNaN()' function instead.

Apr 03 2026

The analyzer detected a comparison of a float type variable with math.NaN(). Even if the variable has the value math.NaN(), any check of math.NaN() using comparison operators results incorrectly.

Look at the example:

func Foo(a float64) {
  if a == math.NaN() {
    ....
  }
}

Checking the variable for NaN using the == operator will always return false. Instead, use the math.IsNaN function.

The fixed code snippet:

func Foo(a float64) {
  if math.IsNaN(a) {
    ....
  }
}

This diagnostic rule is classified as: