diff options
Diffstat (limited to 'src/math/big/floatconv_test.go')
-rw-r--r-- | src/math/big/floatconv_test.go | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/math/big/floatconv_test.go b/src/math/big/floatconv_test.go index fffcd70ce6..656d28c975 100644 --- a/src/math/big/floatconv_test.go +++ b/src/math/big/floatconv_test.go @@ -11,9 +11,12 @@ import ( ) func TestFloatSetFloat64String(t *testing.T) { + inf := math.Inf(0) + nan := math.NaN() + for _, test := range []struct { s string - x float64 + x float64 // NaNs represent invalid inputs }{ // basics {"0", 0}, @@ -45,6 +48,25 @@ func TestFloatSetFloat64String(t *testing.T) { {"1.E+10", 1e10}, {"+1E-10", 1e-10}, + // infinities + {"Inf", inf}, + {"+Inf", inf}, + {"-Inf", -inf}, + {"inf", inf}, + {"+inf", inf}, + {"-inf", -inf}, + + // invalid numbers + {"", nan}, + {"-", nan}, + {"0x", nan}, + {"0e", nan}, + {"1.2ef", nan}, + {"2..3", nan}, + {"123..", nan}, + {"infinity", nan}, + {"foobar", nan}, + // misc decimal values {"3.14159265", 3.14159265}, {"-687436.79457e-245", -687436.79457e-245}, @@ -96,8 +118,16 @@ func TestFloatSetFloat64String(t *testing.T) { var x Float x.SetPrec(53) _, ok := x.SetString(test.s) + if math.IsNaN(test.x) { + // test.s is invalid + if ok { + t.Errorf("%s: want parse error", test.s) + } + continue + } + // test.s is valid if !ok { - t.Errorf("%s: parse error", test.s) + t.Errorf("%s: got parse error", test.s) continue } f, _ := x.Float64() |