github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/math/cmplx/example_test.go (about) 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 5 package cmplx_test 6 7 import ( 8 "fmt" 9 "math" 10 "math/cmplx" 11 ) 12 13 func ExampleAbs() { 14 fmt.Printf("%.1f", cmplx.Abs(3+4i)) 15 // Output: 5.0 16 } 17 18 // ExampleExp computes Euler's identity. 19 func ExampleExp() { 20 fmt.Printf("%.1f", cmplx.Exp(1i*math.Pi)+1) 21 // Output: (0.0+0.0i) 22 } 23 24 func ExamplePolar() { 25 r, theta := cmplx.Polar(2i) 26 fmt.Printf("r: %.1f, θ: %.1f*π", r, theta/math.Pi) 27 // Output: r: 2.0, θ: 0.5*π 28 }