Skip to content

Commit 7b4a224

Browse files
alexd765bradfitz
authored andcommitted
math/cmplx: add examples for Abs, Exp, Polar
Updates #16360 Change-Id: I941519981ff5bda3a113e14fa6be718eb4d2bf83 Reviewed-on: https://go-review.googlesource.com/30554 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 1c09b4d commit 7b4a224

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/math/cmplx/example_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)