mirror of
https://github.com/golang/go
synced 2024-11-24 22:00:09 -07:00
strconv: fix bug in extended-float based conversion.
A test intended for denormals erroneously returned true also for infinities, leading to bad overflows and wrong error estimates. R=rsc CC=golang-dev, remy https://golang.org/cl/5489091
This commit is contained in:
parent
fc78c5aa00
commit
2afebbdf35
@ -114,6 +114,9 @@ var atoftests = []atofTest{
|
|||||||
{"2.2250738585072012e-308", "2.2250738585072014e-308", nil},
|
{"2.2250738585072012e-308", "2.2250738585072014e-308", nil},
|
||||||
// http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/
|
// http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/
|
||||||
{"2.2250738585072011e-308", "2.225073858507201e-308", nil},
|
{"2.2250738585072011e-308", "2.225073858507201e-308", nil},
|
||||||
|
|
||||||
|
// A very large number (initially wrongly parsed by the fast algorithm).
|
||||||
|
{"4.630813248087435e+307", "4.630813248087435e+307", nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
type atofSimpleTest struct {
|
type atofSimpleTest struct {
|
||||||
@ -200,7 +203,7 @@ func TestAtofRandom(t *testing.T) {
|
|||||||
x, _ := ParseFloat(test.s, 64)
|
x, _ := ParseFloat(test.s, 64)
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
t.Errorf("number %s badly parsed as %b (expected %b)", test.s, test.x, x)
|
t.Errorf("number %s badly parsed as %b (expected %b)", test.s, x, test.x)
|
||||||
case x == test.x:
|
case x == test.x:
|
||||||
case math.IsNaN(test.x) && math.IsNaN(x):
|
case math.IsNaN(test.x) && math.IsNaN(x):
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ func (f *extFloat) AssignDecimal(d *decimal) (ok bool) {
|
|||||||
const denormalExp = -1023 - 63
|
const denormalExp = -1023 - 63
|
||||||
flt := &float64info
|
flt := &float64info
|
||||||
var extrabits uint
|
var extrabits uint
|
||||||
if f.exp <= denormalExp || f.exp >= 1023-64 {
|
if f.exp <= denormalExp {
|
||||||
extrabits = uint(63 - flt.mantbits + 1 + uint(denormalExp-f.exp))
|
extrabits = uint(63 - flt.mantbits + 1 + uint(denormalExp-f.exp))
|
||||||
} else {
|
} else {
|
||||||
extrabits = uint(63 - flt.mantbits)
|
extrabits = uint(63 - flt.mantbits)
|
||||||
|
Loading…
Reference in New Issue
Block a user