summaryrefslogtreecommitdiff
path: root/src/pkg/fmt/format.go
diff options
context:
space:
mode:
authorAndrei Vieru <euvieru@gmail.com>2010-04-12 10:20:06 -0700
committerAndrei Vieru <euvieru@gmail.com>2010-04-12 10:20:06 -0700
commite2999f34536f2e18de3aad5e328608678323d6b1 (patch)
tree07fedad4c35c36165acd658fd206f9037e155b11 /src/pkg/fmt/format.go
parent7a54cbb2aa40b7f7825f95830cb6f7b3eb346bd6 (diff)
downloadgolang-e2999f34536f2e18de3aad5e328608678323d6b1.tar.gz
fmt format verb %b bug
fmt.Printf("%b", int8(-1)) prints 64 ones instead of 8. This happens only for signed integers (int8, in16 and int32). I guess it's because of the way the conversion between integer types works. From go spec: "Conversions between integer types. If the value is a signed quantity, it is sign extended to implicit infinite precision ....". And there are several conversions to int64 and uint64 in the fmt package. This pathch solves only half of the problem. On a 32 bit system, an fmt.Printf("%b", int(-1)) should still print 64 ones. R=golang-dev, r CC=golang-dev http://codereview.appspot.com/891049 Committer: Rob Pike <r@golang.org>
Diffstat (limited to 'src/pkg/fmt/format.go')
-rw-r--r--src/pkg/fmt/format.go11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go
index 137c355bb..2637eb4cd 100644
--- a/src/pkg/fmt/format.go
+++ b/src/pkg/fmt/format.go
@@ -306,14 +306,11 @@ func (f *fmt) fmt_uo32(v uint32) { f.integer(int64(v), 8, unsigned, ldigits) }
// fmt_uo formats a uint in octal.
func (f *fmt) fmt_uo(v uint) { f.integer(int64(v), 8, unsigned, ldigits) }
-// fmt_b64 formats a uint64 in binary.
-func (f *fmt) fmt_b64(v uint64) { f.integer(int64(v), 2, unsigned, ldigits) }
+// fmt_b64 formats an int64 in binary.
+func (f *fmt) fmt_b64(v int64) { f.integer(v, 2, signed, ldigits) }
-// fmt_b32 formats a uint32 in binary.
-func (f *fmt) fmt_b32(v uint32) { f.integer(int64(v), 2, unsigned, ldigits) }
-
-// fmt_b formats a uint in binary.
-func (f *fmt) fmt_b(v uint) { f.integer(int64(v), 2, unsigned, ldigits) }
+// fmt_ub64 formats a uint64 in binary.
+func (f *fmt) fmt_ub64(v uint64) { f.integer(int64(v), 2, unsigned, ldigits) }
// fmt_c formats a Unicode character.
func (f *fmt) fmt_c(v int) { f.padString(string(v)) }