Commit 5e74d409 authored by Robert Griesemer's avatar Robert Griesemer

strconv: fix ParseFloat for special forms of zero values

Fixes #15364.

Change-Id: Id2a349896064c7c9e00e36c55162068bf18162b2
Reviewed-on: https://go-review.googlesource.com/22272Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent ba756301
...@@ -244,7 +244,9 @@ func readFloat(s string) (mantissa uint64, exp int, neg, trunc, ok bool) { ...@@ -244,7 +244,9 @@ func readFloat(s string) (mantissa uint64, exp int, neg, trunc, ok bool) {
return return
} }
if mantissa != 0 {
exp = dp - ndMant exp = dp - ndMant
}
ok = true ok = true
return return
......
...@@ -42,6 +42,30 @@ var atoftests = []atofTest{ ...@@ -42,6 +42,30 @@ var atoftests = []atofTest{
{"1e-20", "1e-20", nil}, {"1e-20", "1e-20", nil},
{"625e-3", "0.625", nil}, {"625e-3", "0.625", nil},
// zeros
{"0", "0", nil},
{"0e0", "0", nil},
{"-0e0", "-0", nil},
{"+0e0", "0", nil},
{"0e-0", "0", nil},
{"-0e-0", "-0", nil},
{"+0e-0", "0", nil},
{"0e+0", "0", nil},
{"-0e+0", "-0", nil},
{"+0e+0", "0", nil},
{"0e+01234567890123456789", "0", nil},
{"0.00e-01234567890123456789", "0", nil},
{"-0e+01234567890123456789", "-0", nil},
{"-0.00e-01234567890123456789", "-0", nil},
{"0e291", "0", nil}, // issue 15364
{"0e292", "0", nil}, // issue 15364
{"0e347", "0", nil}, // issue 15364
{"0e348", "0", nil}, // issue 15364
{"-0e291", "-0", nil},
{"-0e292", "-0", nil},
{"-0e347", "-0", nil},
{"-0e348", "-0", nil},
// NaNs // NaNs
{"nan", "NaN", nil}, {"nan", "NaN", nil},
{"NaN", "NaN", nil}, {"NaN", "NaN", nil},
......
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