aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-02-10 14:51:16 -0800
committerRobert Griesemer <gri@golang.org>2015-02-11 17:02:54 +0000
commit15fe15a198ef15d925f9d32f38fd4bb5734e4802 (patch)
tree98aca8484cf8f0b5662d549b417d3183168c6679 /src/math/big/float_test.go
parent64e70382915daee094c64189514d7366a91d242a (diff)
downloadgo-15fe15a198ef15d925f9d32f38fd4bb5734e4802.tar.xz
math/big: add test cases for Float.Abs and Float.Neg
Change-Id: Ic5f3864bc6d94d60b754e3ccf72b1d40c5c09117 Reviewed-on: https://go-review.googlesource.com/4510 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/float_test.go')
-rw-r--r--src/math/big/float_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go
index 8e6490e15d..58fab4605a 100644
--- a/src/math/big/float_test.go
+++ b/src/math/big/float_test.go
@@ -593,6 +593,53 @@ func TestFloatRat(t *testing.T) {
// TODO(gri) implement this
}
+func TestFloatAbs(t *testing.T) {
+ for _, test := range []string{
+ "0",
+ "1",
+ "1234",
+ "1.23e-2",
+ "1e-1000",
+ "1e1000",
+ "Inf",
+ } {
+ p := makeFloat(test)
+ a := new(Float).Abs(p)
+ if !feq(a, p) {
+ t.Errorf("%s: got %s; want %s", test, a.Format('g', 10), test)
+ }
+
+ n := makeFloat("-" + test)
+ a.Abs(n)
+ if !feq(a, p) {
+ t.Errorf("-%s: got %s; want %s", test, a.Format('g', 10), test)
+ }
+ }
+}
+
+func TestFloatNeg(t *testing.T) {
+ for _, test := range []string{
+ "0",
+ "1",
+ "1234",
+ "1.23e-2",
+ "1e-1000",
+ "1e1000",
+ "Inf",
+ } {
+ p1 := makeFloat(test)
+ n1 := makeFloat("-" + test)
+ n2 := new(Float).Neg(p1)
+ p2 := new(Float).Neg(n2)
+ if !feq(n2, n1) {
+ t.Errorf("%s: got %s; want %s", test, n2.Format('g', 10), n1.Format('g', 10))
+ }
+ if !feq(p2, p1) {
+ t.Errorf("%s: got %s; want %s", test, p2.Format('g', 10), p1.Format('g', 10))
+ }
+ }
+}
+
// Selected precisions with which to run various tests.
var precList = [...]uint{1, 2, 5, 8, 10, 16, 23, 24, 32, 50, 53, 64, 100, 128, 500, 511, 512, 513, 1000, 10000}