]> Cypherpunks repositories - gostls13.git/commit
fmt format verb %b bug
authorAndrei Vieru <euvieru@gmail.com>
Mon, 12 Apr 2010 17:20:06 +0000 (10:20 -0700)
committerRob Pike <r@golang.org>
Mon, 12 Apr 2010 17:20:06 +0000 (10:20 -0700)
commit1ab15fac22484a13835e1d3dee25f68e1c7ba9e0
tree74396b6742c24ff7472789036058b5c21123d580
parent8a68b8287bf0e4df70a615f7250f2ee300e961cd
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
https://golang.org/cl/891049
src/pkg/fmt/fmt_test.go
src/pkg/fmt/format.go
src/pkg/fmt/print.go