math: fix Pow10 loop

Pow10 failed for MinInt32 (endless loop until out of
memory).  Fix by returning 0 and +Inf for all arguments
where the result is not representable in a float64.
Fixes #2159.

R=rsc
CC=golang-dev
https://golang.org/cl/4930041
diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go
index d2a7d41..1fe4513 100644
--- a/src/pkg/math/all_test.go
+++ b/src/pkg/math/all_test.go
@@ -1359,6 +1359,20 @@
 	NaN(),           // pow(NaN, NaN)
 }
 
+var vfpow10SC = []int{
+	MinInt32,
+	MaxInt32,
+	-325,
+	309,
+}
+
+var pow10SC = []float64{
+	0,      // pow10(MinInt32)
+	Inf(1), // pow10(MaxInt32)
+	0,      // pow10(-325)
+	Inf(1), // pow10(309)
+}
+
 var vfsignbitSC = []float64{
 	Inf(-1),
 	Copysign(0, -1),
@@ -2143,6 +2157,14 @@
 	}
 }
 
+func TestPow10(t *testing.T) {
+	for i := 0; i < len(vfpow10SC); i++ {
+		if f := Pow10(vfpow10SC[i]); !alike(pow10SC[i], f) {
+			t.Errorf("Pow10(%d) = %g, want %g", vfpow10SC[i], f, pow10SC[i])
+		}
+	}
+}
+
 func TestRemainder(t *testing.T) {
 	for i := 0; i < len(vf); i++ {
 		if f := Remainder(10, vf[i]); remainder[i] != f {
@@ -2659,6 +2681,18 @@
 	}
 }
 
+func BenchmarkPow10Pos(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		Pow10(300)
+	}
+}
+
+func BenchmarkPow10Neg(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		Pow10(-300)
+	}
+}
+
 func BenchmarkRemainder(b *testing.B) {
 	for i := 0; i < b.N; i++ {
 		Remainder(10, 3)