1// Copyright 2010 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package cmplx
6
7import "math"
8
9// IsNaN reports whether either real(x) or imag(x) is NaN
10// and neither is an infinity.
11func IsNaN(x complex128) bool {
12	switch {
13	case math.IsInf(real(x), 0) || math.IsInf(imag(x), 0):
14		return false
15	case math.IsNaN(real(x)) || math.IsNaN(imag(x)):
16		return true
17	}
18	return false
19}
20
21// NaN returns a complex ``not-a-number'' value.
22func NaN() complex128 {
23	nan := math.NaN()
24	return complex(nan, nan)
25}
26