]> Cypherpunks repositories - gostls13.git/commitdiff
math: add examples for Log, Log2, Mod, and Abs
authorMichael Brandenburg <mcbrande@gmail.com>
Wed, 19 Jun 2019 05:16:05 +0000 (22:16 -0700)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Wed, 19 Jun 2019 07:09:13 +0000 (07:09 +0000)
Change-Id: I5f57acd5e970b3fec5f33cfceee179235cbf739f
Reviewed-on: https://go-review.googlesource.com/c/go/+/182877
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/math/example_test.go

index 25d6975903bcbbf9c25f75e59e811452a4029345..364891324a01bcac9b5fc0bbef3a93b323688566 100644 (file)
@@ -135,3 +135,41 @@ func ExampleRoundToEven() {
        // 12.0
        // 12.0
 }
+
+func ExampleLog() {
+       x := math.Log(1)
+       fmt.Printf("%.1f\n", x)
+
+       y := math.Log(2.7183)
+       fmt.Printf("%.1f\n", y)
+       // Output:
+       // 0.0
+       // 1.0
+}
+
+func ExampleLog2() {
+       fmt.Printf("%.1f", math.Log2(256))
+       // Output: 8.0
+}
+
+func ExampleLog10() {
+       fmt.Printf("%.1f", math.Log10(100))
+       // Output: 2.0
+}
+
+func ExampleMod() {
+       c := math.Mod(7, 4)
+       fmt.Printf("%.1f", c)
+       // Output: 3.0
+}
+
+func ExampleAbs() {
+       x := math.Abs(-2)
+       fmt.Printf("%.1f\n", x)
+
+       y := math.Abs(2)
+       fmt.Printf("%.1f\n", y)
+       // Output:
+       // 2.0
+       // 2.0
+}