aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-01-30 14:53:53 -0800
committerRobert Griesemer <gri@golang.org>2015-01-30 23:03:06 +0000
commitf17cd880895863e2c13396296819d0dce81fa43f (patch)
tree388b07704de7a148d687a0ffcf2f53d2e4ec188d /src/math/big/float_test.go
parent20a96a1f68cfe608b8066f3ee1b0db28d1d3e4e0 (diff)
downloadgo-f17cd880895863e2c13396296819d0dce81fa43f.tar.xz
math/big: split float conversion routines and tests into separate files
No other functional changes. Change-Id: I7e0bb7452c6a265535297ec7ce6a629f1aff695c Reviewed-on: https://go-review.googlesource.com/3674 Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/float_test.go')
-rw-r--r--src/math/big/float_test.go101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go
index 940cb6d353..3281f2745a 100644
--- a/src/math/big/float_test.go
+++ b/src/math/big/float_test.go
@@ -682,104 +682,3 @@ func TestFromBits(t *testing.T) {
}
}
}
-
-var floatSetFloat64StringTests = []struct {
- s string
- x float64
-}{
- {"0", 0},
- {"-0", -0},
- {"+0", 0},
- {"1", 1},
- {"-1", -1},
- {"+1", 1},
- {"1.234", 1.234},
- {"-1.234", -1.234},
- {"+1.234", 1.234},
- {".1", 0.1},
- {"1.", 1},
- {"+1.", 1},
-
- {"0e100", 0},
- {"-0e+100", 0},
- {"+0e-100", 0},
- {"0E100", 0},
- {"-0E+100", 0},
- {"+0E-100", 0},
- {"0p100", 0},
- {"-0p+100", 0},
- {"+0p-100", 0},
-
- {"1.e10", 1e10},
- {"1e+10", 1e10},
- {"+1e-10", 1e-10},
- {"1E10", 1e10},
- {"1.E+10", 1e10},
- {"+1E-10", 1e-10},
- {"1p10", 1 << 10},
- {"1p+10", 1 << 10},
- {"+1.p-10", 1.0 / (1 << 10)},
-
- {"-687436.79457e-245", -687436.79457e-245},
- {"-687436.79457E245", -687436.79457e245},
- {"1024.p-12", 0.25},
- {"-1.p10", -1024},
- {"0.25p2", 1},
-
- {".0000000000000000000000000000000000000001", 1e-40},
- {"+10000000000000000000000000000000000000000e-0", 1e40},
-}
-
-func TestFloatSetFloat64String(t *testing.T) {
- for _, test := range floatSetFloat64StringTests {
- var x Float
- x.prec = 53 // TODO(gri) find better solution
- _, ok := x.SetString(test.s)
- if !ok {
- t.Errorf("%s: parse error", test.s)
- continue
- }
- f, _ := x.Float64()
- want := new(Float).SetFloat64(test.x)
- if x.Cmp(want) != 0 {
- t.Errorf("%s: got %s (%v); want %v", test.s, &x, f, test.x)
- }
- }
-}
-
-func TestFloatFormat(t *testing.T) {
- for _, test := range []struct {
- x string
- format byte
- prec int
- want string
- }{
- {"0", 'b', 0, "0"},
- {"-0", 'b', 0, "-0"},
- {"1.0", 'b', 0, "4503599627370496p1"},
- {"-1.0", 'b', 0, "-4503599627370496p1"},
-
- {"0", 'p', 0, "0"},
- {"-0", 'p', 0, "-0"},
- {"1024.0", 'p', 0, "0x.8p11"},
- {"-1024.0", 'p', 0, "-0x.8p11"},
- } {
- f64, err := strconv.ParseFloat(test.x, 64)
- if err != nil {
- t.Error(err)
- continue
- }
- f := new(Float).SetFloat64(f64)
- got := f.Format(test.format, test.prec)
- if got != test.want {
- t.Errorf("%v: got %s", test, got)
- }
- if test.format == 'b' || test.format == 'p' {
- continue // 'b', 'p' format not supported or different in strconv.Format
- }
- want := strconv.FormatFloat(f64, test.format, test.prec, 64)
- if got != want {
- t.Errorf("%v: got %s; want %s", test, got, want)
- }
- }
-}