exp.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // The original C code, the long comment, and the constants
  7. // below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c.
  8. // The go code is a simplified version of the original C.
  9. //
  10. // Cephes Math Library Release 2.8: June, 2000
  11. // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
  12. //
  13. // The readme file at http://netlib.sandia.gov/cephes/ says:
  14. // Some software in this archive may be from the book _Methods and
  15. // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster
  16. // International, 1989) or from the Cephes Mathematical Library, a
  17. // commercial product. In either event, it is copyrighted by the author.
  18. // What you see here may be used freely but it comes with no support or
  19. // guarantee.
  20. //
  21. // The two known misprints in the book are repaired here in the
  22. // source listings for the gamma function and the incomplete beta
  23. // integral.
  24. //
  25. // Stephen L. Moshier
  26. // moshier@na-net.ornl.gov
  27. // Complex exponential function
  28. //
  29. // DESCRIPTION:
  30. //
  31. // Returns the complex exponential of the complex argument z.
  32. //
  33. // If
  34. // z = x + iy,
  35. // r = exp(x),
  36. // then
  37. // w = r cos y + i r sin y.
  38. //
  39. // ACCURACY:
  40. //
  41. // Relative error:
  42. // arithmetic domain # trials peak rms
  43. // DEC -10,+10 8700 3.7e-17 1.1e-17
  44. // IEEE -10,+10 30000 3.0e-16 8.7e-17
  45. // Exp returns e**x, the base-e exponential of x.
  46. func Exp(x complex128) complex128 {
  47. r := math.Exp(real(x))
  48. s, c := math.Sincos(imag(x))
  49. return complex(r*c, r*s)
  50. }