diff options
| author | Robert Griesemer <gri@golang.org> | 2015-02-03 15:13:26 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2015-02-04 21:07:37 +0000 |
| commit | b8fcae02b076cdef0bbef5bce5de090409858fba (patch) | |
| tree | e294167d869d48372020a0d20ed09bad9a3af477 /src/math/big/floatconv.go | |
| parent | bbd6771621247d77075cc71ad49a6a8d6cc076a7 (diff) | |
| download | go-b8fcae02b076cdef0bbef5bce5de090409858fba.tar.xz | |
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 <adonovan@google.com>
Diffstat (limited to 'src/math/big/floatconv.go')
| -rw-r--r-- | src/math/big/floatconv.go | 12 |
1 files changed, 5 insertions, 7 deletions
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 |
