diff options
| author | Michael Brandenburg <mcbrande@gmail.com> | 2019-06-18 22:16:05 -0700 |
|---|---|---|
| committer | Emmanuel Odeke <emm.odeke@gmail.com> | 2019-06-19 07:09:13 +0000 |
| commit | 18107ed9fbdb0d2ae1006857e21a8a66882e12dd (patch) | |
| tree | 52bfab2b8be05fa9470f313c28a7a6c0419bf971 /src/math | |
| parent | 1962dc88eb89cd37d3f9f85e8e4b7ad4915db089 (diff) | |
| download | go-18107ed9fbdb0d2ae1006857e21a8a66882e12dd.tar.xz | |
math: add examples for Log, Log2, Mod, and Abs
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>
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/example_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/math/example_test.go b/src/math/example_test.go index 25d6975903..364891324a 100644 --- a/src/math/example_test.go +++ b/src/math/example_test.go @@ -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 +} |
