1
0
mirror of https://github.com/golang/go synced 2024-11-23 14:30:02 -07:00

strconv: fix ParseFloat for special forms of zero values

Fixes #15364.

Change-Id: Id2a349896064c7c9e00e36c55162068bf18162b2
Reviewed-on: https://go-review.googlesource.com/22272
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Robert Griesemer 2016-04-19 14:42:15 -07:00
parent ba7563019f
commit 5e74d40952
2 changed files with 27 additions and 1 deletions

View File

@ -244,7 +244,9 @@ func readFloat(s string) (mantissa uint64, exp int, neg, trunc, ok bool) {
return
}
exp = dp - ndMant
if mantissa != 0 {
exp = dp - ndMant
}
ok = true
return

View File

@ -42,6 +42,30 @@ var atoftests = []atofTest{
{"1e-20", "1e-20", 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
{"nan", "NaN", nil},
{"NaN", "NaN", nil},