From: Josh Bleecher Snyder Date: Thu, 4 May 2017 15:41:49 +0000 (-0700) Subject: go/constant: avoid generating rats for large negative exponents X-Git-Tag: go1.9beta1~334 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8d63408f4688ff577c25f07a1728fe131d0cae2a;p=gostls13.git go/constant: avoid generating rats for large negative exponents Fixes #20228 Change-Id: I1893ae3e192da01f9befe5469b2a32e534a691ba Reviewed-on: https://go-review.googlesource.com/42592 Reviewed-by: Robert Griesemer --- diff --git a/src/go/constant/value.go b/src/go/constant/value.go index e9b6087bae..5474e73e24 100644 --- a/src/go/constant/value.go +++ b/src/go/constant/value.go @@ -247,6 +247,13 @@ func makeFloatFromLiteral(lit string) Value { if f, ok := newFloat().SetString(lit); ok { if smallRat(f) { // ok to use rationals + if f.Sign() == 0 { + // Issue 20228: If the float underflowed to zero, parse just "0". + // Otherwise, lit might contain a value with a large negative exponent, + // such as -6e-1886451601. As a float, that will underflow to 0, + // but it'll take forever to parse as a Rat. + lit = "0" + } r, _ := newRat().SetString(lit) return ratVal{r} } diff --git a/src/go/constant/value_test.go b/src/go/constant/value_test.go index 8a8a08eaaa..954a0e05db 100644 --- a/src/go/constant/value_test.go +++ b/src/go/constant/value_test.go @@ -244,7 +244,8 @@ var stringTests = []struct { {"1e9999", "1e+9999", "0x.f8d4a9da224650a8cb2959e10d985ad92adbd44c62917e608b1f24c0e1b76b6f61edffeb15c135a4b601637315f7662f325f82325422b244286a07663c9415d2p+33216"}, {"1e-9999", "1e-9999", "0x.83b01ba6d8c0425eec1b21e96f7742d63c2653ed0a024cf8a2f9686df578d7b07d7a83d84df6a2ec70a921d1f6cd5574893a7eda4d28ee719e13a5dce2700759p-33215"}, {"2.71828182845904523536028747135266249775724709369995957496696763", "2.71828", "271828182845904523536028747135266249775724709369995957496696763/100000000000000000000000000000000000000000000000000000000000000"}, - {"0e9999999999", "0", "0"}, // issue #16176 + {"0e9999999999", "0", "0"}, // issue #16176 + {"-6e-1886451601", "0", "0"}, // issue #20228 // Complex {"0i", "(0 + 0i)", "(0 + 0i)"},