Commit 8d63408f authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

go/constant: avoid generating rats for large negative exponents

Fixes #20228

Change-Id: I1893ae3e192da01f9befe5469b2a32e534a691ba
Reviewed-on: https://go-review.googlesource.com/42592Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent d62c6c3c
......@@ -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}
}
......
......@@ -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)"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment