]> Cypherpunks repositories - gostls13.git/commitdiff
math: add Round and RoundToEven examples
authorEric Ponce <tricokun@gmail.com>
Sun, 26 Aug 2018 17:32:07 +0000 (19:32 +0200)
committerIan Lance Taylor <iant@golang.org>
Tue, 28 Aug 2018 05:22:41 +0000 (05:22 +0000)
Change-Id: Ibef5f96ea588d17eac1c96ee3992e01943ba0fef
Reviewed-on: https://go-review.googlesource.com/131496
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/math/example_test.go

index a1f764bcdaabcba7b9aed385bbe4c4f9947b242b..25d6975903bcbbf9c25f75e59e811452a4029345 100644 (file)
@@ -113,3 +113,25 @@ func ExamplePow10() {
        fmt.Printf("%.1f", c)
        // Output: 100.0
 }
+
+func ExampleRound() {
+       p := math.Round(10.5)
+       fmt.Printf("%.1f\n", p)
+
+       n := math.Round(-10.5)
+       fmt.Printf("%.1f\n", n)
+       // Output:
+       // 11.0
+       // -11.0
+}
+
+func ExampleRoundToEven() {
+       u := math.RoundToEven(11.5)
+       fmt.Printf("%.1f\n", u)
+
+       d := math.RoundToEven(12.5)
+       fmt.Printf("%.1f\n", d)
+       // Output:
+       // 12.0
+       // 12.0
+}