aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/floatconv.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-05-22 13:58:03 -0700
committerRobert Griesemer <gri@golang.org>2015-05-22 23:12:51 +0000
commit2df1ccdbc6aac9e570e985437d741d723cb3497c (patch)
treed502df4099b123bcfbdfef51a11d4fe774dae984 /src/math/big/floatconv.go
parent22e4b8167f14bdd33738cfdc21c3396b2341f8fd (diff)
downloadgo-2df1ccdbc6aac9e570e985437d741d723cb3497c.tar.xz
math/big: Always print exponent sign when using 'p' exponent for Floats.
Float.Format supports the 'b' and 'p' format, both of which print a binary ('p') exponent. The 'b' format always printed a sign ('+' or '-') for the exponent; the 'p' format only printed a negative sign for the exponent. This change makes the two consistent. It also makes the 'p' format easier to read if the exponent is >= 0. Also: - Comments added elsewhere. Change-Id: Ifd2e01bdafb3043345972ca22a90248d055bd29b Reviewed-on: https://go-review.googlesource.com/10359 Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/floatconv.go')
-rw-r--r--src/math/big/floatconv.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/math/big/floatconv.go b/src/math/big/floatconv.go
index b929d1202c..5ab75e9031 100644
--- a/src/math/big/floatconv.go
+++ b/src/math/big/floatconv.go
@@ -67,6 +67,7 @@ func (z *Float) SetString(s string) (*Float, bool) {
// defined if an error is reported.
//
// BUG(gri) The Float.Scan signature conflicts with Scan(s fmt.ScanState, ch rune) error.
+// (https://github.com/golang/go/issues/10938)
func (z *Float) Scan(r io.ByteScanner, base int) (f *Float, b int, err error) {
prec := z.prec
if prec == 0 {
@@ -268,6 +269,8 @@ func ParseFloat(s string, base int, prec uint, mode RoundingMode) (f *Float, b i
// The prec value is ignored for the 'b' or 'p' format.
//
// BUG(gri) Float.Format does not accept negative precisions.
+// BUG(gri) The Float.Format signature conflicts with Format(f fmt.State, c rune).
+// (https://github.com/golang/go/issues/10938)
func (x *Float) Format(format byte, prec int) string {
const extra = 10 // TODO(gri) determine a good/better value here
return string(x.Append(make([]byte, 0, prec+extra), format, prec))
@@ -369,5 +372,8 @@ func (x *Float) pstring(buf []byte) []byte {
buf = append(buf, "0x."...)
buf = append(buf, strings.TrimRight(x.mant.hexString(), "0")...)
buf = append(buf, 'p')
+ if x.exp >= 0 {
+ buf = append(buf, '+')
+ }
return strconv.AppendInt(buf, int64(x.exp), 10)
}