summaryrefslogtreecommitdiff
path: root/src/pkg/fmt/format.go
diff options
context:
space:
mode:
authorKen Thompson <ken@golang.org>2010-03-06 11:26:33 -0800
committerKen Thompson <ken@golang.org>2010-03-06 11:26:33 -0800
commit99b5b934de44abf56c783ffe835b547032393b33 (patch)
tree00d1e829f9db80ffcd887325d4ecce75335a7ae7 /src/pkg/fmt/format.go
parent5842cfc85c6f8fc4d21a8eed092e072c31e8d57f (diff)
downloadgolang-99b5b934de44abf56c783ffe835b547032393b33.tar.gz
PTAL
R=r CC=golang-dev http://codereview.appspot.com/254043
Diffstat (limited to 'src/pkg/fmt/format.go')
-rw-r--r--src/pkg/fmt/format.go54
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 {