A common mistake is treating NaN like an ordinary number. NaN (Not-a-Number) represents an undefined or unrepresentable floating-point result. Under IEEE-754, it is the only floating-point value for which f != f. section 3.3
Constructing special floating-point values
A zero-valued float64 can produce positive infinity, negative infinity, and NaN: var a float64 positiveInf := 1 / a negativeInf := -1 / a nan := a / a fmt.Println(positiveInf, negativeInf, nan) // +Inf -Inf NaN section 3.3
var a float64 positiveInf := 1 / a negativeInf := -1 / a nan := a / a fmt.Println(positiveInf, negativeInf, nan) +Inf -Inf NaN
Constructs positive infinity, negative infinity, and NaN from float64 arithmetic. section 3.3
Use the value’s special behavior when diagnosing results:
- Check for NaN with math.IsNaN rather than relying on ordinary equality. section 3.3
- Treat NaN as evidence that an earlier floating-point operation was undefined or unrepresentable. section 3.3








