Commit a370fbaa authored by Robert Griesemer's avatar Robert Griesemer

math/big: use more direct formatting in ExampleRoundingMode, cosmetic changes

Change-Id: I3d37391af2089881a5bd4d8f3e5d434b279c272e
Reviewed-on: https://go-review.googlesource.com/14490Reviewed-by: default avatarChris Manghane <cmang@golang.org>
parent 3ed6e830
...@@ -113,9 +113,9 @@ func ExampleFloat_Cmp() { ...@@ -113,9 +113,9 @@ func ExampleFloat_Cmp() {
func ExampleRoundingMode() { func ExampleRoundingMode() {
operands := []float64{2.6, 2.5, 2.1, -2.1, -2.5, -2.6} 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++ { for mode := big.ToNearestEven; mode <= big.ToPositiveInf; mode++ {
fmt.Printf(" %s", mode) fmt.Printf(" %s", mode)
} }
fmt.Println() fmt.Println()
...@@ -125,18 +125,17 @@ func ExampleRoundingMode() { ...@@ -125,18 +125,17 @@ func ExampleRoundingMode() {
// sample operands above require 2 bits to represent mantissa // sample operands above require 2 bits to represent mantissa
// set binary precision to 2 to round them to integer values // set binary precision to 2 to round them to integer values
f := new(big.Float).SetPrec(2).SetMode(mode).SetFloat64(f64) f := new(big.Float).SetPrec(2).SetMode(mode).SetFloat64(f64)
format := fmt.Sprintf(" %%%dg", len(mode.String())) fmt.Printf(" %*g", len(mode.String()), f)
fmt.Printf(format, f)
} }
fmt.Println() fmt.Println()
} }
// Output: // Output:
// x ToNearestEven ToNearestAway ToZero AwayFromZero ToNegativeInf ToPositiveInf // x ToNearestEven ToNearestAway ToZero AwayFromZero ToNegativeInf ToPositiveInf
// 2.6 3 3 2 3 2 3 // 2.6 3 3 2 3 2 3
// 2.5 2 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 2 3
// -2.1 -2 -2 -2 -3 -3 -2 // -2.1 -2 -2 -2 -3 -3 -2
// -2.5 -2 -3 -2 -3 -3 -2 // -2.5 -2 -3 -2 -3 -3 -2
// -2.6 -3 -3 -2 -3 -3 -2 // -2.6 -3 -3 -2 -3 -3 -2
} }
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