1
0
mirror of https://github.com/golang/go synced 2024-09-25 15:20:13 -06:00

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
This commit is contained in:
Rob Pike 2013-09-15 10:45:36 +10:00
parent 04c40c97c3
commit 89dacb9cca
3 changed files with 10 additions and 2 deletions

View File

@ -227,6 +227,8 @@ var fmtTests = []struct {
{"%+.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
{"%+.3e", 0i, "(+0.000e+00+0.000e+00i)"},
@ -247,6 +249,8 @@ var fmtTests = []struct {
{"% .3E", -1 - 2i, "(-1.000E+00-2.000E+00i)"},
{"%+.3g", complex64(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
{"", 2, "%!(EXTRA int=2)"},

View File

@ -429,6 +429,8 @@ func (f *fmt) fmt_c64(v complex64, verb rune) {
oldPlus := f.plus
for i := 0; ; i++ {
switch verb {
case 'b':
f.fmt_fb32(r)
case 'e':
f.fmt_e32(r)
case 'E':
@ -457,6 +459,8 @@ func (f *fmt) fmt_c128(v complex128, verb rune) {
oldPlus := f.plus
for i := 0; ; i++ {
switch verb {
case 'b':
f.fmt_fb64(r)
case 'e':
f.fmt_e64(r)
case 'E':

View File

@ -511,7 +511,7 @@ func (p *pp) fmtFloat64(v float64, verb rune) {
func (p *pp) fmtComplex64(v complex64, verb rune) {
switch verb {
case 'e', 'E', 'f', 'F', 'g', 'G':
case 'b', 'e', 'E', 'f', 'F', 'g', 'G':
p.fmt.fmt_c64(v, verb)
case 'v':
p.fmt.fmt_c64(v, 'g')
@ -522,7 +522,7 @@ func (p *pp) fmtComplex64(v complex64, verb rune) {
func (p *pp) fmtComplex128(v complex128, verb rune) {
switch verb {
case 'e', 'E', 'f', 'F', 'g', 'G':
case 'b', 'e', 'E', 'f', 'F', 'g', 'G':
p.fmt.fmt_c128(v, verb)
case 'v':
p.fmt.fmt_c128(v, 'g')