internal/encoding/text: format using 32 bitsize when encoding float32

When encoding/textpb marshals out float32 values, it was previously
formatting it as float64 bitsize since both float types are stored as
float64 and internal/encoding/text only has one Float type.  A
consequence of this is that the output may display a different value
than expected, e.g.  1.02 becomes 1.0199999809265137.

This CL splits Float type into Float32 and Float64 to keep track of
which bitsize to use when formatting.  Values of both types are still
stored as float64 to keep the logic simple.

Decoding will always use Float64, but users can ask for a float32 value
from it.

Change-Id: Iea5b14b283fec2236a0c3946fac34d4d79b95274
Reviewed-on: https://go-review.googlesource.com/c/158497
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/encoding/textpb/encode_test.go b/encoding/textpb/encode_test.go
index fe4271d..9c79761 100644
--- a/encoding/textpb/encode_test.go
+++ b/encoding/textpb/encode_test.go
@@ -162,9 +162,8 @@
 			OptSint64:   scalar.Int64(-0xffff),
 			OptFixed64:  scalar.Uint64(64),
 			OptSfixed32: scalar.Int32(-32),
-			// TODO: Update encoder to output same decimals.
-			OptFloat:  scalar.Float32(1.02),
-			OptDouble: scalar.Float64(1.23e100),
+			OptFloat:    scalar.Float32(1.02),
+			OptDouble:   scalar.Float64(1.0199999809265137),
 			// TODO: Update encoder to not output UTF8 for bytes.
 			OptBytes:  []byte("\xe8\xb0\xb7\xe6\xad\x8c"),
 			OptString: scalar.String("谷歌"),
@@ -178,8 +177,8 @@
 opt_sint64: -65535
 opt_fixed64: 64
 opt_sfixed32: -32
-opt_float: 1.0199999809265137
-opt_double: 1.23e+100
+opt_float: 1.02
+opt_double: 1.0199999809265137
 opt_bytes: "谷歌"
 opt_string: "谷歌"
 `,
@@ -449,7 +448,7 @@
 			RptInt64:  []int64{-64, 47},
 			RptUint32: []uint32{0xff, 0xffff},
 			RptUint64: []uint64{0xdeadbeef},
-			// TODO: add float32 examples.
+			RptFloat:  []float32{float32(math.NaN()), float32(math.Inf(1)), float32(math.Inf(-1)), 1.034},
 			RptDouble: []float64{math.NaN(), math.Inf(1), math.Inf(-1), 1.23e-308},
 			RptString: []string{"hello", "世界"},
 			RptBytes: [][]byte{
@@ -470,6 +469,10 @@
 rpt_uint32: 255
 rpt_uint32: 65535
 rpt_uint64: 3735928559
+rpt_float: nan
+rpt_float: inf
+rpt_float: -inf
+rpt_float: 1.034
 rpt_double: nan
 rpt_double: inf
 rpt_double: -inf