Commit 18107ed9 authored by Michael Brandenburg's avatar Michael Brandenburg Committed by Emmanuel Odeke

math: add examples for Log, Log2, Mod, and Abs

Change-Id: I5f57acd5e970b3fec5f33cfceee179235cbf739f
Reviewed-on: https://go-review.googlesource.com/c/go/+/182877Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1962dc88
......@@ -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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment