fmtTest{"% .3g", -1.0, "-1"},
fmtTest{"% .3g", 1.0, " 1"},
+ /* TODO: Enable when complex support is in all compilers
+ // complex values
+ fmtTest{"%+.3e", 0i, "(+0.000e+00+0.000e+00i)"},
+ fmtTest{"%+.3f", 0i, "(+0.000+0.000i)"},
+ fmtTest{"%+.3g", 0i, "(+0+0i)"},
+ fmtTest{"%+.3e", 1 + 2i, "(+1.000e+00+2.000e+00i)"},
+ fmtTest{"%+.3f", 1 + 2i, "(+1.000+2.000i)"},
+ fmtTest{"%+.3g", 1 + 2i, "(+1+2i)"},
+ fmtTest{"%.3e", 0i, "(0.000e+00+0.000e+00i)"},
+ fmtTest{"%.3f", 0i, "(0.000+0.000i)"},
+ fmtTest{"%.3g", 0i, "(0+0i)"},
+ fmtTest{"%.3e", 1 + 2i, "(1.000e+00+2.000e+00i)"},
+ fmtTest{"%.3f", 1 + 2i, "(1.000+2.000i)"},
+ fmtTest{"%.3g", 1 + 2i, "(1+2i)"},
+ fmtTest{"%.3e", -1 - 2i, "(-1.000e+00-2.000e+00i)"},
+ fmtTest{"%.3f", -1 - 2i, "(-1.000-2.000i)"},
+ fmtTest{"%.3g", -1 - 2i, "(-1-2i)"},
+ fmtTest{"% .3E", -1 - 2i, "(-1.000E+00-2.000E+00i)"},
+ fmtTest{"%+.3g", complex64(1 + 2i), "(+1+2i)"},
+ fmtTest{"%+.3g", complex128(1 + 2i), "(+1+2i)"},
+ */
+
// erroneous formats
fmtTest{"", 2, "?(extra int=2)"},
fmtTest{"%d", "hello", "%d(string=hello)"},
fmtTest{"%v", &array, "&[1 2 3 4 5]"},
fmtTest{"%v", &iarray, "&[1 hello 2.5 <nil>]"},
+ /* TODO: Enable when complex support is in all compilers
+ // complexes with %v
+ fmtTest{"%v", 1 + 2i, "(1+2i)"},
+ fmtTest{"%v", complex64(1 + 2i), "(1+2i)"},
+ fmtTest{"%v", complex128(1 + 2i), "(1+2i)"},
+ */
+
// structs
fmtTest{"%v", A{1, 2, "a", []int{1, 2}}, `{1 2 a [1 2]}`},
fmtTest{"%+v", A{1, 2, "a", []int{1, 2}}, `{i:1 j:2 s:a x:[1 2]}`},
wid int
prec int
// flags
- widPresent bool
- precPresent bool
- minus bool
- plus bool
- sharp bool
- space bool
- zero bool
+ widPresent bool
+ precPresent bool
+ minus bool
+ plus bool
+ sharp bool
+ space bool
+ zero bool
+ preserveFlags bool // don't clear flags after this print; used to carry over in complex prints
}
func (f *fmt) clearflags() {
if right > 0 {
f.writePadding(right, padding)
}
- f.clearflags()
+ if !f.preserveFlags {
+ f.clearflags()
+ }
}
// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus).
if right > 0 {
f.writePadding(right, padding)
}
- f.clearflags()
+ if !f.preserveFlags {
+ f.clearflags()
+ }
}
func putint(buf []byte, base, val uint64, digits string) int {
func (f *fmt) fmt_c64(v complex64, fmt_x byte) {
f.buf.WriteByte('(')
r := real(v)
+ f.preserveFlags = true
for i := 0; ; i++ {
switch fmt_x {
case 'e':
case 'G':
f.fmt_G32(r)
}
+ f.preserveFlags = false
if i != 0 {
break
}
func (f *fmt) fmt_c128(v complex128, fmt_x byte) {
f.buf.WriteByte('(')
r := real(v)
+ f.preserveFlags = true
for i := 0; ; i++ {
switch fmt_x {
case 'e':
case 'G':
f.fmt_G64(r)
}
+ f.preserveFlags = false
if i != 0 {
break
}