isnan.go 796 B

1234567891011121314151617181920212223242526272829
  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. // Copyright ©2017 The Gonum Authors. All rights reserved.
  5. // Use of this source code is governed by a BSD-style
  6. // license that can be found in the LICENSE file.
  7. package cmplx64
  8. import math "gonum.org/v1/gonum/internal/math32"
  9. // IsNaN returns true if either real(x) or imag(x) is NaN
  10. // and neither is an infinity.
  11. func IsNaN(x complex64) 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. // NaN returns a complex ``not-a-number'' value.
  21. func NaN() complex64 {
  22. nan := math.NaN()
  23. return complex(nan, nan)
  24. }