• Andrei Vieru's avatar
    fmt format verb %b bug · 1ab15fac
    Andrei Vieru authored
    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
    1ab15fac
print.go 25.8 KB