Commit 89dacb9c authored by Rob Pike's avatar Rob Pike

fmt: %b for complex64 and complex128

Just an oversight they were missing.
Fixes #6387

R=golang-dev, dominik.honnef, rsc
CC=golang-dev
https://golang.org/cl/13715043
parent 04c40c97
...@@ -227,6 +227,8 @@ var fmtTests = []struct { ...@@ -227,6 +227,8 @@ var fmtTests = []struct {
{"%+.3g", -1.0, "-1"}, {"%+.3g", -1.0, "-1"},
{"% .3g", -1.0, "-1"}, {"% .3g", -1.0, "-1"},
{"% .3g", 1.0, " 1"}, {"% .3g", 1.0, " 1"},
{"%b", float32(1.0), "8388608p-23"},
{"%b", 1.0, "4503599627370496p-52"},
// complex values // complex values
{"%+.3e", 0i, "(+0.000e+00+0.000e+00i)"}, {"%+.3e", 0i, "(+0.000e+00+0.000e+00i)"},
...@@ -247,6 +249,8 @@ var fmtTests = []struct { ...@@ -247,6 +249,8 @@ var fmtTests = []struct {
{"% .3E", -1 - 2i, "(-1.000E+00-2.000E+00i)"}, {"% .3E", -1 - 2i, "(-1.000E+00-2.000E+00i)"},
{"%+.3g", complex64(1 + 2i), "(+1+2i)"}, {"%+.3g", complex64(1 + 2i), "(+1+2i)"},
{"%+.3g", complex128(1 + 2i), "(+1+2i)"}, {"%+.3g", complex128(1 + 2i), "(+1+2i)"},
{"%b", complex64(1 + 2i), "(8388608p-23+8388608p-22i)"},
{"%b", 1 + 2i, "(4503599627370496p-52+4503599627370496p-51i)"},
// erroneous formats // erroneous formats
{"", 2, "%!(EXTRA int=2)"}, {"", 2, "%!(EXTRA int=2)"},
......
...@@ -429,6 +429,8 @@ func (f *fmt) fmt_c64(v complex64, verb rune) { ...@@ -429,6 +429,8 @@ func (f *fmt) fmt_c64(v complex64, verb rune) {
oldPlus := f.plus oldPlus := f.plus
for i := 0; ; i++ { for i := 0; ; i++ {
switch verb { switch verb {
case 'b':
f.fmt_fb32(r)
case 'e': case 'e':
f.fmt_e32(r) f.fmt_e32(r)
case 'E': case 'E':
...@@ -457,6 +459,8 @@ func (f *fmt) fmt_c128(v complex128, verb rune) { ...@@ -457,6 +459,8 @@ func (f *fmt) fmt_c128(v complex128, verb rune) {
oldPlus := f.plus oldPlus := f.plus
for i := 0; ; i++ { for i := 0; ; i++ {
switch verb { switch verb {
case 'b':
f.fmt_fb64(r)
case 'e': case 'e':
f.fmt_e64(r) f.fmt_e64(r)
case 'E': case 'E':
......
...@@ -511,7 +511,7 @@ func (p *pp) fmtFloat64(v float64, verb rune) { ...@@ -511,7 +511,7 @@ func (p *pp) fmtFloat64(v float64, verb rune) {
func (p *pp) fmtComplex64(v complex64, verb rune) { func (p *pp) fmtComplex64(v complex64, verb rune) {
switch verb { switch verb {
case 'e', 'E', 'f', 'F', 'g', 'G': case 'b', 'e', 'E', 'f', 'F', 'g', 'G':
p.fmt.fmt_c64(v, verb) p.fmt.fmt_c64(v, verb)
case 'v': case 'v':
p.fmt.fmt_c64(v, 'g') p.fmt.fmt_c64(v, 'g')
...@@ -522,7 +522,7 @@ func (p *pp) fmtComplex64(v complex64, verb rune) { ...@@ -522,7 +522,7 @@ func (p *pp) fmtComplex64(v complex64, verb rune) {
func (p *pp) fmtComplex128(v complex128, verb rune) { func (p *pp) fmtComplex128(v complex128, verb rune) {
switch verb { switch verb {
case 'e', 'E', 'f', 'F', 'g', 'G': case 'b', 'e', 'E', 'f', 'F', 'g', 'G':
p.fmt.fmt_c128(v, verb) p.fmt.fmt_c128(v, verb)
case 'v': case 'v':
p.fmt.fmt_c128(v, 'g') p.fmt.fmt_c128(v, 'g')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment