From 00c73f5c6e4b80a24eb19218c006c8a3f08e1ed8 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 5 Mar 2015 17:32:57 -0800 Subject: 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 --- src/math/big/floatconv.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/math/big/floatconv.go') 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 { -- cgit v1.3-5-g45d5