mirror of
https://github.com/golang/go
synced 2024-11-20 04:54:44 -07:00
fmt: fix %v of complex slice
Fixes #4525. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/6929049
This commit is contained in:
parent
15353d2114
commit
07cc05864c
@ -476,6 +476,11 @@ var fmttests = []struct {
|
||||
|
||||
// Used to crash because nByte didn't allow for a sign.
|
||||
{"%b", int64(-1 << 63), "-1000000000000000000000000000000000000000000000000000000000000000"},
|
||||
|
||||
// Complex fmt used to leave the plus flag set for future entries in the array
|
||||
// causing +2+0i and +3+0i instead of 2+0i and 3+0i.
|
||||
{"%v", []complex64{1, 2, 3}, "[(1+0i) (2+0i) (3+0i)]"},
|
||||
{"%v", []complex128{1, 2, 3}, "[(1+0i) (2+0i) (3+0i)]"},
|
||||
}
|
||||
|
||||
func TestSprintf(t *testing.T) {
|
||||
|
@ -428,6 +428,7 @@ func (f *fmt) fmt_fb32(v float32) { f.formatFloat(float64(v), 'b', 0, 32) }
|
||||
func (f *fmt) fmt_c64(v complex64, verb rune) {
|
||||
f.buf.WriteByte('(')
|
||||
r := real(v)
|
||||
oldPlus := f.plus
|
||||
for i := 0; ; i++ {
|
||||
switch verb {
|
||||
case 'e':
|
||||
@ -447,6 +448,7 @@ func (f *fmt) fmt_c64(v complex64, verb rune) {
|
||||
f.plus = true
|
||||
r = imag(v)
|
||||
}
|
||||
f.plus = oldPlus
|
||||
f.buf.Write(irparenBytes)
|
||||
}
|
||||
|
||||
@ -454,6 +456,7 @@ func (f *fmt) fmt_c64(v complex64, verb rune) {
|
||||
func (f *fmt) fmt_c128(v complex128, verb rune) {
|
||||
f.buf.WriteByte('(')
|
||||
r := real(v)
|
||||
oldPlus := f.plus
|
||||
for i := 0; ; i++ {
|
||||
switch verb {
|
||||
case 'e':
|
||||
@ -473,5 +476,6 @@ func (f *fmt) fmt_c128(v complex128, verb rune) {
|
||||
f.plus = true
|
||||
r = imag(v)
|
||||
}
|
||||
f.plus = oldPlus
|
||||
f.buf.Write(irparenBytes)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user