summaryrefslogtreecommitdiff
path: root/src/pkg/fmt/format.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-12-06 12:03:52 -0800
committerRob Pike <r@golang.org>2009-12-06 12:03:52 -0800
commit25ce0349b3305d038c757b2a49c91c7ca05848c9 (patch)
tree9ca97cb7ed859f7cc96604a32683841585024c79 /src/pkg/fmt/format.go
parent956d8c7dec13e1a90061f81c321d6ccd588a3a6e (diff)
downloadgolang-25ce0349b3305d038c757b2a49c91c7ca05848c9.tar.gz
Make printing faster by avoiding mallocs and some other advances.
Roughly 33% faster for simple cases, probably more for complex ones. Before: mallocs per Sprintf(""): 4 mallocs per Sprintf("xxx"): 6 mallocs per Sprintf("%x"): 10 mallocs per Sprintf("%x %x"): 12 Now: mallocs per Sprintf(""): 2 mallocs per Sprintf("xxx"): 3 mallocs per Sprintf("%x"): 5 mallocs per Sprintf("%x %x"): 7 Speed improves because of avoiding mallocs and also by sharing a bytes.Buffer between print.go and format.go rather than copying the data back after each printed item. Before: fmt_test.BenchmarkSprintfEmpty 1000000 1346 ns/op fmt_test.BenchmarkSprintfString 500000 3461 ns/op fmt_test.BenchmarkSprintfInt 500000 3671 ns/op Now: fmt_test.BenchmarkSprintfEmpty 2000000 995 ns/op fmt_test.BenchmarkSprintfString 1000000 2745 ns/op fmt_test.BenchmarkSprintfInt 1000000 2391 ns/op fmt_test.BenchmarkSprintfIntInt 500000 3751 ns/op I believe there is more to get but this is a good milestone. R=rsc CC=golang-dev, hong http://codereview.appspot.com/166076
Diffstat (limited to 'src/pkg/fmt/format.go')
-rw-r--r--src/pkg/fmt/format.go398
1 files changed, 184 insertions, 214 deletions
diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go
index c7b7b9bf3..d09f3522f 100644
--- a/src/pkg/fmt/format.go
+++ b/src/pkg/fmt/format.go
@@ -5,6 +5,7 @@
package fmt
import (
+ "bytes";
"strconv";
)
@@ -16,34 +17,30 @@ const (
udigits = "0123456789ABCDEF";
)
-const padZeros = "0000000000000000000000000000000000000000000000000000000000000000"
-const padSpaces = " "
+var padZeroBytes = make([]byte, nByte)
+var padSpaceBytes = make([]byte, nByte)
+
+var newline = []byte{'\n'}
func init() {
- if len(padZeros) != nByte || len(padSpaces) != nByte {
- panic("fmt padding wrong length")
+ for i := 0; i < nByte; i++ {
+ padZeroBytes[i] = '0';
+ padSpaceBytes[i] = ' ';
}
}
/*
Fmt is the raw formatter used by Printf etc. Not meant for normal use.
+ It prints into a bytes.Buffer that must be set up externally.
See print.go for a more palatable interface.
-
- The model is to accumulate operands into an internal buffer and then
- retrieve the buffer in one hit using Str(), Putnl(), etc. The formatting
- methods return ``self'' so the operations can be chained.
-
- f := fmt.New();
- print(f.Fmt_d(1234).Fmt_s("\n").Str()); // create string, print it
- f.Fmt_d(-1234).Fmt_s("\n").Put(); // print string
- f.Fmt_ud(1<<63).Putnl(); // print string with automatic newline
*/
type Fmt struct {
- buf string;
+ intbuf [nByte]byte;
+ buf *bytes.Buffer;
wid int;
- wid_present bool;
+ widPresent bool;
prec int;
- prec_present bool;
+ precPresent bool;
// flags
minus bool;
plus bool;
@@ -52,11 +49,11 @@ type Fmt struct {
zero bool;
}
-func (f *Fmt) clearflags() {
+func (f *Fmt) ClearFlags() {
f.wid = 0;
- f.wid_present = false;
+ f.widPresent = false;
f.prec = 0;
- f.prec_present = false;
+ f.precPresent = false;
f.minus = false;
f.plus = false;
f.sharp = false;
@@ -64,94 +61,98 @@ func (f *Fmt) clearflags() {
f.zero = false;
}
-func (f *Fmt) clearbuf() { f.buf = "" }
-
-func (f *Fmt) init() {
- f.clearbuf();
- f.clearflags();
+func (f *Fmt) Init(buf *bytes.Buffer) {
+ f.buf = buf;
+ f.ClearFlags();
}
-// New returns a new initialized Fmt
-func New() *Fmt {
- f := new(Fmt);
- f.init();
- return f;
-}
-
-// Str returns the buffered contents as a string and resets the Fmt.
-func (f *Fmt) Str() string {
- s := f.buf;
- f.clearbuf();
- f.clearflags();
- f.buf = "";
- return s;
-}
-
-// Put writes the buffered contents to stdout and resets the Fmt.
-func (f *Fmt) Put() {
- print(f.buf);
- f.clearbuf();
- f.clearflags();
-}
-
-// Putnl writes the buffered contents to stdout, followed by a newline, and resets the Fmt.
-func (f *Fmt) Putnl() {
- print(f.buf, "\n");
- f.clearbuf();
- f.clearflags();
-}
+func (f *Fmt) Reset() { f.ClearFlags() }
// Wp sets the width and precision for formatting the next item.
-func (f *Fmt) Wp(w, p int) *Fmt {
- f.wid_present = true;
+func (f *Fmt) Wp(w, p int) {
+ f.widPresent = true;
f.wid = w;
- f.prec_present = true;
+ f.precPresent = true;
f.prec = p;
- return f;
}
// P sets the precision for formatting the next item.
-func (f *Fmt) P(p int) *Fmt {
- f.prec_present = true;
+func (f *Fmt) P(p int) {
+ f.precPresent = true;
f.prec = p;
- return f;
}
// W sets the width for formatting the next item.
-func (f *Fmt) W(x int) *Fmt {
- f.wid_present = true;
+func (f *Fmt) W(x int) {
+ f.widPresent = true;
f.wid = x;
- return f;
}
-// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus)
-// padding is in bytes, not characters (agrees with ANSIC C, not Plan 9 C)
-func (f *Fmt) pad(s string) {
- if f.wid_present && f.wid != 0 {
- left := !f.minus;
- w := f.wid;
- if w < 0 {
- left = false;
- w = -w;
- }
- w -= len(s);
- padding := padSpaces;
+// Compute left and right padding widths (only one will be non-zero).
+func (f *Fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) {
+ left := !f.minus;
+ w := f.wid;
+ if w < 0 {
+ left = false;
+ w = -w;
+ }
+ w -= width;
+ if w > 0 {
if left && f.zero {
- padding = padZeros
+ return padZeroBytes, w, 0
}
- if w > 0 {
- if w > nByte {
- w = nByte
- }
- padding = padding[0:w];
- if left {
- s = padding + s
- } else {
- s += padding
- }
+ if left {
+ return padSpaceBytes, w, 0
+ } else {
+ // can't be zero padding on the right
+ return padSpaceBytes, 0, w
+ }
+ }
+ return;
+}
+
+// Generate n bytes of padding.
+func (f *Fmt) writePadding(n int, padding []byte) {
+ for n > 0 {
+ m := n;
+ if m > nByte {
+ m = nByte
}
+ f.buf.Write(padding[0:m]);
+ n -= m;
+ }
+}
+
+// Append b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus)
+func (f *Fmt) padBytes(b []byte) {
+ var padding []byte;
+ var left, right int;
+ if f.widPresent && f.wid != 0 {
+ padding, left, right = f.computePadding(len(b))
+ }
+ if left > 0 {
+ f.writePadding(left, padding)
+ }
+ f.buf.Write(b);
+ if right > 0 {
+ f.writePadding(right, padding)
+ }
+}
+
+// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus)
+func (f *Fmt) pad(s string) {
+ var padding []byte;
+ var left, right int;
+ if f.widPresent && f.wid != 0 {
+ padding, left, right = f.computePadding(len(s))
+ }
+ if left > 0 {
+ f.writePadding(left, padding)
+ }
+ f.buf.WriteString(s);
+ if right > 0 {
+ f.writePadding(right, padding)
}
- f.buf += s;
}
// format val into buf, ending at buf[i]. (printing is easier right-to-left;
@@ -171,19 +172,18 @@ func putint(buf []byte, base, val uint64, digits string) int {
}
// Fmt_boolean formats a boolean.
-func (f *Fmt) Fmt_boolean(v bool) *Fmt {
+func (f *Fmt) Fmt_boolean(v bool) {
if v {
f.pad("true")
} else {
f.pad("false")
}
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// integer; interprets prec but not wid.
-func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) string {
- var buf [nByte]byte;
+func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) []byte {
+ var buf []byte = &f.intbuf;
negative := is_signed && a < 0;
if negative {
a = -a
@@ -192,17 +192,17 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) string
// two ways to ask for extra leading zero digits: %.3d or %03d.
// apparently the first cancels the second.
prec := 0;
- if f.prec_present {
+ if f.precPresent {
prec = f.prec;
f.zero = false;
- } else if f.zero && f.wid_present && !f.minus && f.wid > 0 {
+ } else if f.zero && f.widPresent && !f.minus && f.wid > 0 {
prec = f.wid;
if negative || f.plus || f.space {
prec-- // leave room for sign
}
}
- i := putint(&buf, uint64(base), uint64(a), digits);
+ i := putint(buf, uint64(base), uint64(a), digits);
for i > 0 && prec > (nByte-1-i) {
buf[i] = '0';
i--;
@@ -233,147 +233,137 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) string
buf[i] = ' ';
i--;
}
- return string(buf[i+1 : nByte]);
+ return buf[i+1 : nByte];
}
// Fmt_d64 formats an int64 in decimal.
-func (f *Fmt) Fmt_d64(v int64) *Fmt {
- f.pad(f.integer(v, 10, true, ldigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_d64(v int64) {
+ f.padBytes(f.integer(v, 10, true, ldigits));
+ f.ClearFlags();
}
// Fmt_d32 formats an int32 in decimal.
-func (f *Fmt) Fmt_d32(v int32) *Fmt { return f.Fmt_d64(int64(v)) }
+func (f *Fmt) Fmt_d32(v int32) { f.Fmt_d64(int64(v)) }
// Fmt_d formats an int in decimal.
-func (f *Fmt) Fmt_d(v int) *Fmt { return f.Fmt_d64(int64(v)) }
+func (f *Fmt) Fmt_d(v int) { f.Fmt_d64(int64(v)) }
// Fmt_ud64 formats a uint64 in decimal.
func (f *Fmt) Fmt_ud64(v uint64) *Fmt {
- f.pad(f.integer(int64(v), 10, false, ldigits));
- f.clearflags();
+ f.padBytes(f.integer(int64(v), 10, false, ldigits));
+ f.ClearFlags();
return f;
}
// Fmt_ud32 formats a uint32 in decimal.
-func (f *Fmt) Fmt_ud32(v uint32) *Fmt { return f.Fmt_ud64(uint64(v)) }
+func (f *Fmt) Fmt_ud32(v uint32) { f.Fmt_ud64(uint64(v)) }
// Fmt_ud formats a uint in decimal.
-func (f *Fmt) Fmt_ud(v uint) *Fmt { return f.Fmt_ud64(uint64(v)) }
+func (f *Fmt) Fmt_ud(v uint) { f.Fmt_ud64(uint64(v)) }
// Fmt_x64 formats an int64 in hexadecimal.
-func (f *Fmt) Fmt_x64(v int64) *Fmt {
- f.pad(f.integer(v, 16, true, ldigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_x64(v int64) {
+ f.padBytes(f.integer(v, 16, true, ldigits));
+ f.ClearFlags();
}
// Fmt_x32 formats an int32 in hexadecimal.
-func (f *Fmt) Fmt_x32(v int32) *Fmt { return f.Fmt_x64(int64(v)) }
+func (f *Fmt) Fmt_x32(v int32) { f.Fmt_x64(int64(v)) }
// Fmt_x formats an int in hexadecimal.
-func (f *Fmt) Fmt_x(v int) *Fmt { return f.Fmt_x64(int64(v)) }
+func (f *Fmt) Fmt_x(v int) { f.Fmt_x64(int64(v)) }
// Fmt_ux64 formats a uint64 in hexadecimal.
-func (f *Fmt) Fmt_ux64(v uint64) *Fmt {
- f.pad(f.integer(int64(v), 16, false, ldigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_ux64(v uint64) {
+ f.padBytes(f.integer(int64(v), 16, false, ldigits));
+ f.ClearFlags();
}
// Fmt_ux32 formats a uint32 in hexadecimal.
-func (f *Fmt) Fmt_ux32(v uint32) *Fmt { return f.Fmt_ux64(uint64(v)) }
+func (f *Fmt) Fmt_ux32(v uint32) { f.Fmt_ux64(uint64(v)) }
// Fmt_ux formats a uint in hexadecimal.
-func (f *Fmt) Fmt_ux(v uint) *Fmt { return f.Fmt_ux64(uint64(v)) }
+func (f *Fmt) Fmt_ux(v uint) { f.Fmt_ux64(uint64(v)) }
// Fmt_X64 formats an int64 in upper case hexadecimal.
-func (f *Fmt) Fmt_X64(v int64) *Fmt {
- f.pad(f.integer(v, 16, true, udigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_X64(v int64) {
+ f.padBytes(f.integer(v, 16, true, udigits));
+ f.ClearFlags();
}
// Fmt_X32 formats an int32 in upper case hexadecimal.
-func (f *Fmt) Fmt_X32(v int32) *Fmt { return f.Fmt_X64(int64(v)) }
+func (f *Fmt) Fmt_X32(v int32) { f.Fmt_X64(int64(v)) }
// Fmt_X formats an int in upper case hexadecimal.
-func (f *Fmt) Fmt_X(v int) *Fmt { return f.Fmt_X64(int64(v)) }
+func (f *Fmt) Fmt_X(v int) { f.Fmt_X64(int64(v)) }
// Fmt_uX64 formats a uint64 in upper case hexadecimal.
-func (f *Fmt) Fmt_uX64(v uint64) *Fmt {
- f.pad(f.integer(int64(v), 16, false, udigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_uX64(v uint64) {
+ f.padBytes(f.integer(int64(v), 16, false, udigits));
+ f.ClearFlags();
}
// Fmt_uX32 formats a uint32 in upper case hexadecimal.
-func (f *Fmt) Fmt_uX32(v uint32) *Fmt { return f.Fmt_uX64(uint64(v)) }
+func (f *Fmt) Fmt_uX32(v uint32) { f.Fmt_uX64(uint64(v)) }
// Fmt_uX formats a uint in upper case hexadecimal.
-func (f *Fmt) Fmt_uX(v uint) *Fmt { return f.Fmt_uX64(uint64(v)) }
+func (f *Fmt) Fmt_uX(v uint) { f.Fmt_uX64(uint64(v)) }
// Fmt_o64 formats an int64 in octal.
-func (f *Fmt) Fmt_o64(v int64) *Fmt {
- f.pad(f.integer(v, 8, true, ldigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_o64(v int64) {
+ f.padBytes(f.integer(v, 8, true, ldigits));
+ f.ClearFlags();
}
// Fmt_o32 formats an int32 in octal.
-func (f *Fmt) Fmt_o32(v int32) *Fmt { return f.Fmt_o64(int64(v)) }
+func (f *Fmt) Fmt_o32(v int32) { f.Fmt_o64(int64(v)) }
// Fmt_o formats an int in octal.
-func (f *Fmt) Fmt_o(v int) *Fmt { return f.Fmt_o64(int64(v)) }
+func (f *Fmt) Fmt_o(v int) { f.Fmt_o64(int64(v)) }
// Fmt_uo64 formats a uint64 in octal.
-func (f *Fmt) Fmt_uo64(v uint64) *Fmt {
- f.pad(f.integer(int64(v), 8, false, ldigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_uo64(v uint64) {
+ f.padBytes(f.integer(int64(v), 8, false, ldigits));
+ f.ClearFlags();
}
// Fmt_uo32 formats a uint32 in octal.
-func (f *Fmt) Fmt_uo32(v uint32) *Fmt { return f.Fmt_uo64(uint64(v)) }
+func (f *Fmt) Fmt_uo32(v uint32) { f.Fmt_uo64(uint64(v)) }
// Fmt_uo formats a uint in octal.
-func (f *Fmt) Fmt_uo(v uint) *Fmt { return f.Fmt_uo64(uint64(v)) }
+func (f *Fmt) Fmt_uo(v uint) { f.Fmt_uo64(uint64(v)) }
// Fmt_b64 formats a uint64 in binary.
-func (f *Fmt) Fmt_b64(v uint64) *Fmt {
- f.pad(f.integer(int64(v), 2, false, ldigits));
- f.clearflags();
- return f;
+func (f *Fmt) Fmt_b64(v uint64) {
+ f.padBytes(f.integer(int64(v), 2, false, ldigits));
+ f.ClearFlags();
}
// Fmt_b32 formats a uint32 in binary.
-func (f *Fmt) Fmt_b32(v uint32) *Fmt { return f.Fmt_b64(uint64(v)) }
+func (f *Fmt) Fmt_b32(v uint32) { f.Fmt_b64(uint64(v)) }
// Fmt_b formats a uint in binary.
-func (f *Fmt) Fmt_b(v uint) *Fmt { return f.Fmt_b64(uint64(v)) }
+func (f *Fmt) Fmt_b(v uint) { f.Fmt_b64(uint64(v)) }
// Fmt_c formats a Unicode character.
-func (f *Fmt) Fmt_c(v int) *Fmt {
+func (f *Fmt) Fmt_c(v int) {
f.pad(string(v));
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// Fmt_s formats a string.
-func (f *Fmt) Fmt_s(s string) *Fmt {
- if f.prec_present {
+func (f *Fmt) Fmt_s(s string) {
+ if f.precPresent {
if f.prec < len(s) {
s = s[0:f.prec]
}
}
f.pad(s);
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// Fmt_sx formats a string as a hexadecimal encoding of its bytes.
-func (f *Fmt) Fmt_sx(s string) *Fmt {
+func (f *Fmt) Fmt_sx(s string) {
t := "";
for i := 0; i < len(s); i++ {
if i > 0 && f.space {
@@ -384,12 +374,11 @@ func (f *Fmt) Fmt_sx(s string) *Fmt {
t += string(ldigits[v&0xF]);
}
f.pad(t);
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// Fmt_sX formats a string as an uppercase hexadecimal encoding of its bytes.
-func (f *Fmt) Fmt_sX(s string) *Fmt {
+func (f *Fmt) Fmt_sX(s string) {
t := "";
for i := 0; i < len(s); i++ {
v := s[i];
@@ -397,12 +386,11 @@ func (f *Fmt) Fmt_sX(s string) *Fmt {
t += string(udigits[v&0xF]);
}
f.pad(t);
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// Fmt_q formats a string as a double-quoted, escaped Go string constant.
-func (f *Fmt) Fmt_q(s string) *Fmt {
+func (f *Fmt) Fmt_q(s string) {
var quoted string;
if f.sharp && strconv.CanBackquote(s) {
quoted = "`" + s + "`"
@@ -410,27 +398,25 @@ func (f *Fmt) Fmt_q(s string) *Fmt {
quoted = strconv.Quote(s)
}
f.pad(quoted);
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// floating-point
func doPrec(f *Fmt, def int) int {
- if f.prec_present {
+ if f.precPresent {
return f.prec
}
return def;
}
-func fmtString(f *Fmt, s string) *Fmt {
+func fmtString(f *Fmt, s string) {
f.pad(s);
- f.clearflags();
- return f;
+ f.ClearFlags();
}
// Add a plus sign or space to the string if missing and required.
-func (f *Fmt) plusSpace(s string) *Fmt {
+func (f *Fmt) plusSpace(s string) {
if s[0] != '-' {
if f.plus {
s = "+" + s
@@ -438,94 +424,78 @@ func (f *Fmt) plusSpace(s string) *Fmt {
s = " " + s
}
}
- return fmtString(f, s);
+ fmtString(f, s);
}
// Fmt_e64 formats a float64 in the form -1.23e+12.
-func (f *Fmt) Fmt_e64(v float64) *Fmt {
- return f.plusSpace(strconv.Ftoa64(v, 'e', doPrec(f, 6)))
-}
+func (f *Fmt) Fmt_e64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'e', doPrec(f, 6))) }
// Fmt_E64 formats a float64 in the form -1.23E+12.
-func (f *Fmt) Fmt_E64(v float64) *Fmt {
- return f.plusSpace(strconv.Ftoa64(v, 'E', doPrec(f, 6)))
-}
+func (f *Fmt) Fmt_E64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'E', doPrec(f, 6))) }
// Fmt_f64 formats a float64 in the form -1.23.
-func (f *Fmt) Fmt_f64(v float64) *Fmt {
- return f.plusSpace(strconv.Ftoa64(v, 'f', doPrec(f, 6)))
-}
+func (f *Fmt) Fmt_f64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'f', doPrec(f, 6))) }
// Fmt_g64 formats a float64 in the 'f' or 'e' form according to size.
-func (f *Fmt) Fmt_g64(v float64) *Fmt {
- return f.plusSpace(strconv.Ftoa64(v, 'g', doPrec(f, -1)))
-}
+func (f *Fmt) Fmt_g64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'g', doPrec(f, -1))) }
// Fmt_g64 formats a float64 in the 'f' or 'E' form according to size.
-func (f *Fmt) Fmt_G64(v float64) *Fmt {
- return f.plusSpace(strconv.Ftoa64(v, 'G', doPrec(f, -1)))
-}
+func (f *Fmt) Fmt_G64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'G', doPrec(f, -1))) }
// Fmt_fb64 formats a float64 in the form -123p3 (exponent is power of 2).
-func (f *Fmt) Fmt_fb64(v float64) *Fmt { return f.plusSpace(strconv.Ftoa64(v, 'b', 0)) }
+func (f *Fmt) Fmt_fb64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'b', 0)) }
// float32
// cannot defer to float64 versions
// because it will get rounding wrong in corner cases.
// Fmt_e32 formats a float32 in the form -1.23e+12.
-func (f *Fmt) Fmt_e32(v float32) *Fmt {
- return f.plusSpace(strconv.Ftoa32(v, 'e', doPrec(f, 6)))
-}
+func (f *Fmt) Fmt_e32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'e', doPrec(f, 6))) }
// Fmt_E32 formats a float32 in the form -1.23E+12.
-func (f *Fmt) Fmt_E32(v float32) *Fmt {
- return f.plusSpace(strconv.Ftoa32(v, 'E', doPrec(f, 6)))
-}
+func (f *Fmt) Fmt_E32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'E', doPrec(f, 6))) }
// Fmt_f32 formats a float32 in the form -1.23.
-func (f *Fmt) Fmt_f32(v float32) *Fmt {
- return f.plusSpace(strconv.Ftoa32(v, 'f', doPrec(f, 6)))
-}
+func (f *Fmt) Fmt_f32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'f', doPrec(f, 6))) }
// Fmt_g32 formats a float32 in the 'f' or 'e' form according to size.
-func (f *Fmt) Fmt_g32(v float32) *Fmt {
- return f.plusSpace(strconv.Ftoa32(v, 'g', doPrec(f, -1)))
-}
+func (f *Fmt) Fmt_g32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'g', doPrec(f, -1))) }
// Fmt_G32 formats a float32 in the 'f' or 'E' form according to size.
-func (f *Fmt) Fmt_G32(v float32) *Fmt {
- return f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f, -1)))
-}
+func (f *Fmt) Fmt_G32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f, -1))) }
// Fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2).
-func (f *Fmt) Fmt_fb32(v float32) *Fmt { return fmtString(f, strconv.Ftoa32(v, 'b', 0)) }
+func (f *Fmt) Fmt_fb32(v float32) { fmtString(f, strconv.Ftoa32(v, 'b', 0)) }
// float
-func (x *Fmt) f(a float) *Fmt {
+func (x *Fmt) f(a float) {
if strconv.FloatSize == 32 {
- return x.Fmt_f32(float32(a))
+ x.Fmt_f32(float32(a))
+ } else {
+ x.Fmt_f64(float64(a))
}
- return x.Fmt_f64(float64(a));
}
-func (x *Fmt) e(a float) *Fmt {
+func (x *Fmt) e(a float) {
if strconv.FloatSize == 32 {
- return x.Fmt_e32(float32(a))
+ x.Fmt_e32(float32(a))
+ } else {
+ x.Fmt_e64(float64(a))
}
- return x.Fmt_e64(float64(a));
}
-func (x *Fmt) g(a float) *Fmt {
+func (x *Fmt) g(a float) {
if strconv.FloatSize == 32 {
- return x.Fmt_g32(float32(a))
+ x.Fmt_g32(float32(a))
+ } else {
+ x.Fmt_g64(float64(a))
}
- return x.Fmt_g64(float64(a));
}
-func (x *Fmt) fb(a float) *Fmt {
+func (x *Fmt) fb(a float) {
if strconv.FloatSize == 32 {
- return x.Fmt_fb32(float32(a))
+ x.Fmt_fb32(float32(a))
+ } else {
+ x.Fmt_fb64(float64(a))
}
- return x.Fmt_fb64(float64(a));
}