Our website uses cookies to enhance your browsing experience.
Accept
to the top

Webinar: Let's make a programming language. Lexer - 29.04

>
>
>
V8018. Comparison with 'math.NaN()'...
menu mobile close menu
Additional information
toggle menu Contents

V8018. Comparison with 'math.NaN()' is meaningless. Use '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) {
    ....
  }
}