isnan.go 596 B

1234567891011121314151617181920212223242526
  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. package cmplx
  5. import "math"
  6. // IsNaN returns true if either real(x) or imag(x) is NaN
  7. // and neither is an infinity.
  8. func IsNaN(x complex128) bool {
  9. switch {
  10. case math.IsInf(real(x), 0) || math.IsInf(imag(x), 0):
  11. return false
  12. case math.IsNaN(real(x)) || math.IsNaN(imag(x)):
  13. return true
  14. }
  15. return false
  16. }
  17. // NaN returns a complex ``not-a-number'' value.
  18. func NaN() complex128 {
  19. nan := math.NaN()
  20. return complex(nan, nan)
  21. }