diff options
| author | Robert Griesemer <gri@golang.org> | 2015-02-27 17:52:12 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2015-03-04 18:22:31 +0000 |
| commit | ea1fafbccdaee0632dbbdd610d24ab2e2ac25cb6 (patch) | |
| tree | 8823ac4f852800b6a97b47025b46f8ab791b211e /src/math/big/float_test.go | |
| parent | e05388335285928b354aa00b9e6ebd3ab4a392b2 (diff) | |
| download | go-ea1fafbccdaee0632dbbdd610d24ab2e2ac25cb6.tar.xz | |
math/big: modified MantExp semantics to enable fast exponent access
Change-Id: I9a6ebb747d5b9756c214bdeb19f60820602d7a24
Reviewed-on: https://go-review.googlesource.com/6340
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/float_test.go')
| -rw-r--r-- | src/math/big/float_test.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go index 6c05167d86..aaf4970785 100644 --- a/src/math/big/float_test.go +++ b/src/math/big/float_test.go @@ -216,7 +216,7 @@ func feq(x, y *Float) bool { func TestFloatMantExp(t *testing.T) { for _, test := range []struct { x string - frac string + mant string exp int }{ {"0", "0", 0}, @@ -231,23 +231,23 @@ func TestFloatMantExp(t *testing.T) { {"-0.125", "-0.5", -2}, } { x := makeFloat(test.x) - frac := makeFloat(test.frac) - f, e := x.MantExp(nil) - if !feq(f, frac) || e != test.exp { - t.Errorf("%s.MantExp(nil) = %s, %d; want %s, %d", test.x, f.Format('g', 10), e, test.frac, test.exp) + mant := makeFloat(test.mant) + m := new(Float) + e := x.MantExp(m) + if !feq(m, mant) || e != test.exp { + t.Errorf("%s.MantExp() = %s, %d; want %s, %d", test.x, m.Format('g', 10), e, test.mant, test.exp) } } } func TestFloatMantExpAliasing(t *testing.T) { x := makeFloat("0.5p10") - z := new(Float) - if m, _ := x.MantExp(z); m != z { - t.Fatalf("Float.MantExp didn't use supplied *Float") - } - if _, e := x.MantExp(x); e != 10 { + if e := x.MantExp(x); e != 10 { t.Fatalf("Float.MantExp aliasing error: got %d; want 10", e) } + if want := makeFloat("0.5"); !feq(x, want) { + t.Fatalf("Float.MantExp aliasing error: got %s; want %s", x.Format('g', 10), want.Format('g', 10)) + } } func TestFloatSetMantExp(t *testing.T) { @@ -281,7 +281,8 @@ func TestFloatSetMantExp(t *testing.T) { t.Errorf("SetMantExp(%s, %d) = %s; want %s", test.frac, test.exp, z.Format('g', 10), test.z) } // test inverse property - if z.SetMantExp(want.MantExp(nil)).Cmp(want) != 0 { + mant := new(Float) + if z.SetMantExp(mant, want.MantExp(mant)).Cmp(want) != 0 { t.Errorf("Inverse property not satisfied: got %s; want %s", z.Format('g', 10), test.z) } } |
