aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-02-24 21:05:12 -0800
committerRobert Griesemer <gri@golang.org>2015-02-25 18:10:42 +0000
commit88cbe09202d54b6cd3f4d8c0fa8b50e13c7372cf (patch)
treed19ec9910b4e275390558da1b3dc8f76e2644a50 /src/math/big/float_test.go
parent4100f7d95c0b51bc366103f91c9c9cad223c4168 (diff)
downloadgo-88cbe09202d54b6cd3f4d8c0fa8b50e13c7372cf.tar.xz
math/big: permit passing of an *Int to Float.Int to avoid allocation
Change-Id: I50e83248357928e56c94b88a8764de828f4f5c76 Reviewed-on: https://go-review.googlesource.com/5890 Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/float_test.go')
-rw-r--r--src/math/big/float_test.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go
index 69e88c3501..6391beea0b 100644
--- a/src/math/big/float_test.go
+++ b/src/math/big/float_test.go
@@ -714,7 +714,7 @@ func TestFloatInt(t *testing.T) {
{"1e+100", "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", Exact},
} {
x := makeFloat(test.x)
- res, acc := x.Int()
+ res, acc := x.Int(nil)
got := "nil"
if res != nil {
got = res.String()
@@ -723,6 +723,15 @@ func TestFloatInt(t *testing.T) {
t.Errorf("%s: got %s (%s); want %s (%s)", test.x, got, acc, test.want, test.acc)
}
}
+
+ // check that supplied *Int is used
+ for _, f := range []string{"0", "1", "-1", "1234"} {
+ x := makeFloat(f)
+ i := new(Int)
+ if res, _ := x.Int(i); res != i {
+ t.Errorf("(%s).Int is not using supplied *Int", f)
+ }
+ }
}
func TestFloatRat(t *testing.T) {
@@ -765,7 +774,7 @@ func TestFloatRat(t *testing.T) {
}
// check that supplied *Rat is used
- for _, f := range []string{"0", "1"} {
+ for _, f := range []string{"0", "1", "-1", "1234"} {
x := makeFloat(f)
r := new(Rat)
if res := x.Rat(r); res != r {