diff options
| author | Robert Griesemer <gri@golang.org> | 2015-03-05 17:32:57 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2015-03-17 16:09:34 +0000 |
| commit | 00c73f5c6e4b80a24eb19218c006c8a3f08e1ed8 (patch) | |
| tree | ddd5b8097f043e85da7bc63cfcad6af61fa069a1 /src/math/big/floatconv.go | |
| parent | 2e7f0a00c337c0a536fafc1d5cb831cb4c76efad (diff) | |
| download | go-00c73f5c6e4b80a24eb19218c006c8a3f08e1ed8.tar.xz | |
math/big: cleaner handling of exponent under/overflow
Fixed several corner-case bugs and added corresponding tests.
Change-Id: I23096b9caeeff0956f65ab59fa91e168d0e47bb8
Reviewed-on: https://go-review.googlesource.com/7001
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/floatconv.go')
| -rw-r--r-- | src/math/big/floatconv.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/math/big/floatconv.go b/src/math/big/floatconv.go index a3d0ff97a8..f6a78b794c 100644 --- a/src/math/big/floatconv.go +++ b/src/math/big/floatconv.go @@ -101,8 +101,6 @@ func (z *Float) Scan(r io.ByteScanner, base int) (f *Float, b int, err error) { } // len(z.mant) > 0 - z.form = finite - // The mantissa may have a decimal point (fcount <= 0) and there // may be a nonzero exponent exp. The decimal point amounts to a // division by b**(-fcount). An exponent means multiplication by @@ -142,7 +140,14 @@ func (z *Float) Scan(r io.ByteScanner, base int) (f *Float, b int, err error) { // we don't need exp anymore // apply 2**exp2 - z.setExp(exp2) + if MinExp <= exp2 && exp2 <= MaxExp { + z.form = finite + z.exp = int32(exp2) + } else { + f = nil + err = fmt.Errorf("exponent overflow") + return + } if exp10 == 0 { // no decimal exponent to consider @@ -160,7 +165,6 @@ func (z *Float) Scan(r io.ByteScanner, base int) (f *Float, b int, err error) { fpowTen := new(Float).SetInt(new(Int).SetBits(powTen)) // apply 10**exp10 - // (uquo and umul do the rounding) if exp10 < 0 { z.uquo(z, fpowTen) } else { |
