aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-09-10 13:06:46 -0700
committerRobert Griesemer <gri@golang.org>2015-09-10 22:10:41 +0000
commita370fbaac64ccd8cb665552caa0f66f163cc8f42 (patch)
tree781ea0f4e55f2ebdc3735160129c6183bd971995 /src
parent3ed6e830b9cb7541e20a19665f4e1c41453170f2 (diff)
downloadgo-a370fbaac64ccd8cb665552caa0f66f163cc8f42.tar.xz
math/big: use more direct formatting in ExampleRoundingMode, cosmetic changes
Change-Id: I3d37391af2089881a5bd4d8f3e5d434b279c272e Reviewed-on: https://go-review.googlesource.com/14490 Reviewed-by: Chris Manghane <cmang@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/math/big/floatexample_test.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/math/big/floatexample_test.go b/src/math/big/floatexample_test.go
index d135243b82..fb799d5a1f 100644
--- a/src/math/big/floatexample_test.go
+++ b/src/math/big/floatexample_test.go
@@ -113,9 +113,9 @@ func ExampleFloat_Cmp() {
func ExampleRoundingMode() {
operands := []float64{2.6, 2.5, 2.1, -2.1, -2.5, -2.6}
- fmt.Printf("x ")
+ fmt.Print(" x")
for mode := big.ToNearestEven; mode <= big.ToPositiveInf; mode++ {
- fmt.Printf(" %s", mode)
+ fmt.Printf(" %s", mode)
}
fmt.Println()
@@ -125,18 +125,17 @@ func ExampleRoundingMode() {
// sample operands above require 2 bits to represent mantissa
// set binary precision to 2 to round them to integer values
f := new(big.Float).SetPrec(2).SetMode(mode).SetFloat64(f64)
- format := fmt.Sprintf(" %%%dg", len(mode.String()))
- fmt.Printf(format, f)
+ fmt.Printf(" %*g", len(mode.String()), f)
}
fmt.Println()
}
// Output:
- // x ToNearestEven ToNearestAway ToZero AwayFromZero ToNegativeInf ToPositiveInf
- // 2.6 3 3 2 3 2 3
- // 2.5 2 3 2 3 2 3
- // 2.1 2 2 2 3 2 3
- // -2.1 -2 -2 -2 -3 -3 -2
- // -2.5 -2 -3 -2 -3 -3 -2
- // -2.6 -3 -3 -2 -3 -3 -2
+ // x ToNearestEven ToNearestAway ToZero AwayFromZero ToNegativeInf ToPositiveInf
+ // 2.6 3 3 2 3 2 3
+ // 2.5 2 3 2 3 2 3
+ // 2.1 2 2 2 3 2 3
+ // -2.1 -2 -2 -2 -3 -3 -2
+ // -2.5 -2 -3 -2 -3 -3 -2
+ // -2.6 -3 -3 -2 -3 -3 -2
}