aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJavier <javism@gmail.com>2019-09-15 12:20:58 +0800
committerRobert Griesemer <gri@golang.org>2019-09-17 23:05:29 +0000
commit5cc64141e738b008b62d0698cdbadf2b9aead72d (patch)
tree182dd13d75660a3fc59b299aca274e8e732e7fba /src
parentb3e2a72e6f42a924d6489b14c6881aa5cddf9418 (diff)
downloadgo-5cc64141e738b008b62d0698cdbadf2b9aead72d.tar.xz
math: Add examples for Copysign, Dim, Exp* and Trunc
Change-Id: I95921a8a55b243600aaec24ddca74b7040107dca Reviewed-on: https://go-review.googlesource.com/c/go/+/195203 Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/math/example_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/math/example_test.go b/src/math/example_test.go
index 364891324a..50c7426979 100644
--- a/src/math/example_test.go
+++ b/src/math/example_test.go
@@ -44,6 +44,11 @@ func ExampleAtanh() {
// Output: 0.00
}
+func ExampleCopysign() {
+ fmt.Printf("%.2f", math.Copysign(3.2, -1))
+ // Output: -3.20
+}
+
func ExampleCos() {
fmt.Printf("%.2f", math.Cos(math.Pi/2))
// Output: 0.00
@@ -173,3 +178,44 @@ func ExampleAbs() {
// 2.0
// 2.0
}
+func ExampleDim() {
+ fmt.Printf("%.2f\n", math.Dim(4, -2))
+ fmt.Printf("%.2f\n", math.Dim(-4, 2))
+ // Output:
+ // 6.00
+ // 0.00
+}
+
+func ExampleExp() {
+ fmt.Printf("%.2f\n", math.Exp(1))
+ fmt.Printf("%.2f\n", math.Exp(2))
+ fmt.Printf("%.2f\n", math.Exp(-1))
+ // Output:
+ // 2.72
+ // 7.39
+ // 0.37
+}
+
+func ExampleExp2() {
+ fmt.Printf("%.2f\n", math.Exp2(1))
+ fmt.Printf("%.2f\n", math.Exp2(-3))
+ // Output:
+ // 2.00
+ // 0.12
+}
+
+func ExampleExpm1() {
+ fmt.Printf("%.6f\n", math.Expm1(0.01))
+ fmt.Printf("%.6f\n", math.Expm1(-1))
+ // Output:
+ // 0.010050
+ // -0.632121
+}
+
+func ExampleTrunc() {
+ fmt.Printf("%.2f\n", math.Trunc(math.Pi))
+ fmt.Printf("%.2f\n", math.Trunc(-1.2345))
+ // Output:
+ // 3.00
+ // -1.00
+}