diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-02-03 21:58:02 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-02-03 21:58:02 +0000 |
commit | 0694cef2844753fb80be4f71f7d2eb82eb5ba464 (patch) | |
tree | 2f8da9862a9c1fe0df138917f997b03439c02773 /libgo/go/math/big/floatexample_test.go | |
parent | 397fecd695789eccab667bf771a354df71d843e8 (diff) | |
download | gcc-0694cef2844753fb80be4f71f7d2eb82eb5ba464.tar.gz |
libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233110 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/math/big/floatexample_test.go')
-rw-r--r-- | libgo/go/math/big/floatexample_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libgo/go/math/big/floatexample_test.go b/libgo/go/math/big/floatexample_test.go index 69686b7d16b..05bce613a80 100644 --- a/libgo/go/math/big/floatexample_test.go +++ b/libgo/go/math/big/floatexample_test.go @@ -111,3 +111,33 @@ func ExampleFloat_Cmp() { // +Inf 1.2 1 // +Inf +Inf 0 } + +func ExampleRoundingMode() { + operands := []float64{2.6, 2.5, 2.1, -2.1, -2.5, -2.6} + + fmt.Print(" x") + for mode := big.ToNearestEven; mode <= big.ToPositiveInf; mode++ { + fmt.Printf(" %s", mode) + } + fmt.Println() + + for _, f64 := range operands { + fmt.Printf("%4g", f64) + for mode := big.ToNearestEven; mode <= big.ToPositiveInf; mode++ { + // 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) + 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 +} |