From b8fcae02b076cdef0bbef5bce5de090409858fba Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 3 Feb 2015 15:13:26 -0800 Subject: math/big: fix %b format so it matches strconf %b format for non-zero values (For zero values the strconv %b format prints the bias-adjusted exponent; there's no bias in Float.) Change-Id: I6f4dda9c3a50d02eac375cfe2c927c1540aae865 Reviewed-on: https://go-review.googlesource.com/3841 Reviewed-by: Alan Donovan --- src/math/big/floatconv.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/math/big/floatconv.go') diff --git a/src/math/big/floatconv.go b/src/math/big/floatconv.go index a1b234f144..06c1f14471 100644 --- a/src/math/big/floatconv.go +++ b/src/math/big/floatconv.go @@ -205,12 +205,6 @@ func (x *Float) String() string { return x.Format('p', 0) } -// TODO(gri) The 'b' and 'p' formats have different meanings here than -// in strconv: in strconv, the printed exponent is the biased (hardware) -// exponent; here it is the unbiased exponent. Decide what to do. -// (a strconv 'p' formatted float value can only be interpreted correctly -// if the bias is known; i.e., we must know if it's a 32bit or 64bit number). - // bstring appends the string of x in the format ["-"] mantissa "p" exponent // with a decimal mantissa and a binary exponent, or ["-"] "0" if x is zero, // and returns the extended buffer. @@ -233,7 +227,11 @@ func (x *Float) bstring(buf []byte) []byte { } buf = append(buf, m.decimalString()...) buf = append(buf, 'p') - return strconv.AppendInt(buf, int64(x.exp), 10) + e := int64(x.exp) - int64(x.prec) + if e >= 0 { + buf = append(buf, '+') + } + return strconv.AppendInt(buf, e, 10) } // pstring appends the string of x in the format ["-"] "0x." mantissa "p" exponent -- cgit v1.3-5-g9baa