]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: correctly handle large exponent in SetString
authorAlberto Donizetti <alb.donizetti@gmail.com>
Fri, 21 Aug 2015 17:17:18 +0000 (19:17 +0200)
committerRobert Griesemer <gri@golang.org>
Fri, 21 Aug 2015 18:11:22 +0000 (18:11 +0000)
Even though the umul/uquo functions expect two valid, finite big.Floats
arguments, SetString was calling them with possibly Inf values, which
resulted in bogus return values.

Replace umul and udiv calls with Mul and Quo calls to fix this. Also,
fix two wrong tests.

See relevant issue on issue tracker for a detailed explanation.

Fixes #11341

Change-Id: Ie35222763a57a2d712a5f5f7baec75cab8189a53
Reviewed-on: https://go-review.googlesource.com/13778
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/big/floatconv.go
src/math/big/floatconv_test.go

index 4a070ca64d4c835aedad131bb7abb2c6409a6466..0e8b7b649efcd242a30a922f30156625d5c3b2d1 100644 (file)
@@ -125,9 +125,9 @@ func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error) {
        // apply 10**exp10
        p := new(Float).SetPrec(z.Prec() + 64) // use more bits for p -- TODO(gri) what is the right number?
        if exp10 < 0 {
-               z.uquo(z, p.pow10(-exp10))
+               z.Quo(z, p.pow10(-exp10))
        } else {
-               z.umul(z, p.pow10(exp10))
+               z.Mul(z, p.pow10(exp10))
        }
 
        return
index 4f239534a1403b903e56773d19225b5bd14eb02e..156e1af300d32fe9bd3b109657fadae63c054fce 100644 (file)
@@ -367,9 +367,9 @@ func TestFloatText(t *testing.T) {
 
                // make sure "stupid" exponents don't stall the machine
                {"1e1000000", 64, 'p', 0, "0x.88b3a28a05eade3ap+3321929"},
-               {"1e1000000000", 64, 'p', 0, "0x.ecc5f45aa573d3p+1538481529"},
+               {"1e1000000000", 64, 'p', 0, "+Inf"},
                {"1e-1000000", 64, 'p', 0, "0x.efb4542cc8ca418ap-3321928"},
-               {"1e-1000000000", 64, 'p', 0, "0x.8a64dd983a4c7dabp-1538481528"},
+               {"1e-1000000000", 64, 'p', 0, "0"},
 
                // TODO(gri) need tests for actual large Floats