diff options
| author | Robert Griesemer <gri@golang.org> | 2015-02-04 17:17:38 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2015-02-05 22:22:28 +0000 |
| commit | f083a0e364445a9d841ccae732a0391a9e4ddd09 (patch) | |
| tree | 0ef4b987f7505fd2945187e08fa677421631e6ac /src/math/big/float_test.go | |
| parent | 91c0f006fc6f30d970d18ef19407e2a77a2e6acb (diff) | |
| download | go-f083a0e364445a9d841ccae732a0391a9e4ddd09.tar.xz | |
math/big: add "smoke test" for big.Float division
Change-Id: Ica419a1215ca33dc1cff1e9e4137f204591e3cee
Reviewed-on: https://go-review.googlesource.com/3942
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 | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go index ec67a6d606..e37d2ed365 100644 --- a/src/math/big/float_test.go +++ b/src/math/big/float_test.go @@ -521,6 +521,47 @@ func TestFloatQuo(t *testing.T) { } } +// TestFloatQuoSmoke tests all divisions x/y for values x, y in the range [-n, +n]; +// it serves as a smoke test for basic correctness of division. +func TestFloatQuoSmoke(t *testing.T) { + n := 1000 + if testing.Short() { + n = 10 + } + + const dprec = 3 // max. precision variation + const prec = 10 + dprec // enough bits to hold n precisely + for x := -n; x <= n; x++ { + for y := -n; y < n; y++ { + if y == 0 { + continue + } + + a := float64(x) + b := float64(y) + c := a / b + + // vary operand precision (only ok as long as a, b can be represented correctly) + for ad := -dprec; ad <= dprec; ad++ { + for bd := -dprec; bd <= dprec; bd++ { + A := NewFloat(a, uint(prec+ad), 0) + B := NewFloat(b, uint(prec+bd), 0) + C := NewFloat(0, 53, 0).Quo(A, B) // C has float64 mantissa width + + cc, acc := C.Float64() + if cc != c { + t.Errorf("%g/%g = %s; want %.5g\n", a, b, C.Format('g', 5), c) + continue + } + if acc != Exact { + t.Errorf("%g/%g got %s result; want exact result", a, b, acc) + } + } + } + } + } +} + // normBits returns the normalized bits for x: It // removes multiple equal entries by treating them // as an addition (e.g., []int{5, 5} => []int{6}), |
