diff options
Diffstat (limited to 'src/pkg/fmt/format.go')
-rw-r--r-- | src/pkg/fmt/format.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go index 88ef3504e..1567609cf 100644 --- a/src/pkg/fmt/format.go +++ b/src/pkg/fmt/format.go @@ -420,6 +420,60 @@ func (f *fmt) fmt_G32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f, // fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2). func (f *fmt) fmt_fb32(v float32) { f.padString(strconv.Ftoa32(v, 'b', 0)) } +// fmt_c64 formats a complex64 according to its fmt_x argument. +// TODO pass in a method rather than a byte when the compilers mature. +func (f *fmt) fmt_c64(v complex64, fmt_x byte) { + f.buf.WriteByte('(') + r := real(v) + for i := 0; ; i++ { + switch fmt_x { + case 'e': + f.fmt_e32(r) + case 'E': + f.fmt_E32(r) + case 'f': + f.fmt_f32(r) + case 'g': + f.fmt_g32(r) + case 'G': + f.fmt_G32(r) + } + if i != 0 { + break + } + f.plus = true + r = imag(v) + } + f.buf.Write(irparenBytes) +} + +// fmt_c128 formats a complex128 according to its fmt_x argument. +// TODO pass in a method rather than a byte when the compilers mature. +func (f *fmt) fmt_c128(v complex128, fmt_x byte) { + f.buf.WriteByte('(') + r := real(v) + for i := 0; ; i++ { + switch fmt_x { + case 'e': + f.fmt_e64(r) + case 'E': + f.fmt_E64(r) + case 'f': + f.fmt_f64(r) + case 'g': + f.fmt_g64(r) + case 'G': + f.fmt_G64(r) + } + if i != 0 { + break + } + f.plus = true + r = imag(v) + } + f.buf.Write(irparenBytes) +} + // float func (x *fmt) f(a float) { if strconv.FloatSize == 32 { |