aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorRick Hudson <rlh@golang.org>2016-04-27 18:19:16 -0400
committerRick Hudson <rlh@golang.org>2016-04-27 18:46:52 -0400
commit23aeb34df172b17b7bfaa85fb59ca64bef9073bb (patch)
treea8ab866f1e50f0059856ce628f036d93ab620155 /src/strconv
parent1354b32cd70f2702381764fd595dd2faa996840c (diff)
parentd3c79d324acd7300b6f705e66af8ca711af00d9f (diff)
downloadgo-23aeb34df172b17b7bfaa85fb59ca64bef9073bb.tar.xz
[dev.garbage] Merge remote-tracking branch 'origin/master' into HEAD
Change-Id: I282fd9ce9db435dfd35e882a9502ab1abc185297
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/atof.go4
-rw-r--r--src/strconv/atof_test.go24
-rw-r--r--src/strconv/extfloat.go4
3 files changed, 29 insertions, 3 deletions
diff --git a/src/strconv/atof.go b/src/strconv/atof.go
index ce76252340..ada85e9fed 100644
--- a/src/strconv/atof.go
+++ b/src/strconv/atof.go
@@ -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
diff --git a/src/strconv/atof_test.go b/src/strconv/atof_test.go
index 9f70cc1fd7..0a89c3e0bf 100644
--- a/src/strconv/atof_test.go
+++ b/src/strconv/atof_test.go
@@ -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},
diff --git a/src/strconv/extfloat.go b/src/strconv/extfloat.go
index 019b4eebdc..7033e96c39 100644
--- a/src/strconv/extfloat.go
+++ b/src/strconv/extfloat.go
@@ -311,9 +311,9 @@ func (f *extFloat) AssignDecimal(mantissa uint64, exp10 int, neg bool, trunc boo
var extrabits uint
if f.exp <= denormalExp {
// f.mant * 2^f.exp is smaller than 2^(flt.bias+1).
- extrabits = uint(63 - flt.mantbits + 1 + uint(denormalExp-f.exp))
+ extrabits = 63 - flt.mantbits + 1 + uint(denormalExp-f.exp)
} else {
- extrabits = uint(63 - flt.mantbits)
+ extrabits = 63 - flt.mantbits
}
halfway := uint64(1) << (extrabits - 1)