example_test.go 567 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2016 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_test
  5. import (
  6. "fmt"
  7. "math"
  8. "math/cmplx"
  9. )
  10. func ExampleAbs() {
  11. fmt.Printf("%.1f", cmplx.Abs(3+4i))
  12. // Output: 5.0
  13. }
  14. // ExampleExp computes Euler's identity.
  15. func ExampleExp() {
  16. fmt.Printf("%.1f", cmplx.Exp(1i*math.Pi)+1)
  17. // Output: (0.0+0.0i)
  18. }
  19. func ExamplePolar() {
  20. r, theta := cmplx.Polar(2i)
  21. fmt.Printf("r: %.1f, θ: %.1f*π", r, theta/math.Pi)
  22. // Output: r: 2.0, θ: 0.5*π
  23. }