aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-02-13 12:47:44 -0800
committerRobert Griesemer <gri@golang.org>2015-02-14 00:42:05 +0000
commit31e852402fdf36ccc9fd84436d082e960b755cd3 (patch)
tree3c31bbead00b5405ccf58c6cc01f5b9003e77348 /src/math/big/float_test.go
parent7a77d8d1e9b006ae49fd456a8912a8ec03af8ec7 (diff)
downloadgo-31e852402fdf36ccc9fd84436d082e960b755cd3.tar.xz
math/big: fix aliasing error in Add, Sub
Also: - make representation more flexible (no need to store trailing 0 digits to match precision) - simplify rounding as a consequence - minor related fixes TBR adonovan Change-Id: Ie91075990688b506d28371ec3b633b8267397ebb Reviewed-on: https://go-review.googlesource.com/4841 Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/math/big/float_test.go')
-rw-r--r--src/math/big/float_test.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go
index 2f804fa569..be2ac6ff06 100644
--- a/src/math/big/float_test.go
+++ b/src/math/big/float_test.go
@@ -729,14 +729,20 @@ func TestFloatNeg(t *testing.T) {
}
func TestFloatInc(t *testing.T) {
- var x, one Float
- // x.prec = 256 TODO(gri) This doesn't work at the moment
- one.SetInt64(1)
- for i := 0; i < 10; i++ {
- x.Add(&x, &one)
- }
- if s := x.Format('g', 10); s != "10" {
- t.Errorf("got %s; want 10", s)
+ const n = 10
+ for _, prec := range precList {
+ if 1<<prec < n {
+ continue // prec must be large enough to hold all numbers from 0 to n
+ }
+ var x, one Float
+ x.prec = prec
+ one.SetInt64(1)
+ for i := 0; i < n; i++ {
+ x.Add(&x, &one)
+ }
+ if x.Cmp(new(Float).SetInt64(n)) != 0 {
+ t.Errorf("prec = %d: got %s; want %d", prec, &x, n)
+ }
}
}