math/big: various fixes, enable tests for 32bit platforms

- fixed Float.Add, Float.Sub
- fixed Float.PString to be platform independent
- fixed Float.Uint64
- fixed various test outputs

TBR: adonovan

Change-Id: I9d273b344d4786f1fed18862198b23285c358a39
Reviewed-on: https://go-review.googlesource.com/3321
Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go
index 261c4d0..5c46e72 100644
--- a/src/math/big/float_test.go
+++ b/src/math/big/float_test.go
@@ -79,11 +79,6 @@
 
 // TestFloatRound tests basic rounding.
 func TestFloatRound(t *testing.T) {
-	// TODO(gri) fix test for 32bit platforms
-	if _W == 32 {
-		return
-	}
-
 	var tests = []struct {
 		prec                        uint
 		x, zero, neven, naway, away string // input, results rounded to prec bits
@@ -293,11 +288,6 @@
 // respective floating-point addition/subtraction for a variety of precisions
 // and rounding modes.
 func TestFloatAdd(t *testing.T) {
-	// TODO(gri) fix test for 32bit platforms
-	if _W == 32 {
-		return
-	}
-
 	for _, xbits := range bitsList {
 		for _, ybits := range bitsList {
 			// exact values
@@ -308,7 +298,6 @@
 
 			for i, mode := range [...]RoundingMode{ToZero, ToNearestEven, AwayFromZero} {
 				for _, prec := range precList {
-					// +
 					got := NewFloat(0, prec, mode)
 					got.Add(x, y)
 					want := roundBits(zbits, prec, mode)
@@ -318,12 +307,11 @@
 						return
 					}
 
-					// -
 					got.Sub(z, x)
 					want = roundBits(ybits, prec, mode)
 					if got.Cmp(want) != 0 {
-						t.Errorf("i = %d, prec = %d, %s:\n\t     %s\n\t-    %s\n\t=    %s\n\twant %s",
-							i, prec, mode, x, y, got, want)
+						t.Errorf("i = %d, prec = %d, %s:\n\t     %s %v\n\t-    %s %v\n\t=    %s\n\twant %s",
+							i, prec, mode, z, zbits, x, xbits, got, want)
 					}
 				}
 			}
@@ -389,14 +377,14 @@
 			got, acc := z.Float64()
 			want := x0 + y0
 			if got != want || acc != Exact {
-				t.Errorf("d = %d: %g + %g = %g; want %g exactly", d, x0, y0, got, acc, want)
+				t.Errorf("d = %d: %g + %g = %g (%s); want %g exactly", d, x0, y0, got, acc, want)
 			}
 
 			z.Sub(z, y)
 			got, acc = z.Float64()
 			want -= y0
 			if got != want || acc != Exact {
-				t.Errorf("d = %d: %g - %g = %g; want %g exactly", d, x0+y0, y0, got, acc, want)
+				t.Errorf("d = %d: %g - %g = %g (%s); want %g exactly", d, x0+y0, y0, got, acc, want)
 			}
 		}
 	}
@@ -677,29 +665,24 @@
 }
 
 func TestFromBits(t *testing.T) {
-	// TODO(gri) fix test for 32bit platforms
-	if _W == 32 {
-		return
-	}
-
 	var tests = []struct {
 		bits []int
 		want string
 	}{
 		// all different bit numbers
-		{nil, "0.0p0"},
-		{[]int{0}, "0.8000000000000000p1"},
-		{[]int{1}, "0.8000000000000000p2"},
-		{[]int{-1}, "0.8000000000000000p0"},
-		{[]int{63}, "0.8000000000000000p64"},
+		{nil, "0"},
+		{[]int{0}, "0.8p1"},
+		{[]int{1}, "0.8p2"},
+		{[]int{-1}, "0.8p0"},
+		{[]int{63}, "0.8p64"},
 		{[]int{33, -30}, "0.8000000000000001p34"},
 		{[]int{255, 0}, "0.8000000000000000000000000000000000000000000000000000000000000001p256"},
 
 		// multiple equal bit numbers
-		{[]int{0, 0}, "0.8000000000000000p2"},
-		{[]int{0, 0, 0, 0}, "0.8000000000000000p3"},
-		{[]int{0, 1, 0}, "0.8000000000000000p3"},
-		{append([]int{2, 1, 0} /* 7 */, []int{3, 1} /* 10 */ ...), "0.8800000000000000p5" /* 17 */},
+		{[]int{0, 0}, "0.8p2"},
+		{[]int{0, 0, 0, 0}, "0.8p3"},
+		{[]int{0, 1, 0}, "0.8p3"},
+		{append([]int{2, 1, 0} /* 7 */, []int{3, 1} /* 10 */ ...), "0.88p5" /* 17 */},
 	}
 
 	for _, test := range tests {
@@ -779,8 +762,8 @@
 		x    Float
 		want string
 	}{
-		{Float{}, "0.0p0"},
-		{Float{neg: true}, "-0.0p0"},
+		{Float{}, "0"},
+		{Float{neg: true}, "-0"},
 		{Float{mant: nat{0x87654321}}, "0.87654321p0"},
 		{Float{mant: nat{0x87654321}, exp: -10}, "0.87654321p-10"},
 	}