2008-03-27 01:06:21 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package fmt
|
|
|
|
|
2008-11-24 15:51:33 -07:00
|
|
|
import (
|
|
|
|
"strconv";
|
|
|
|
)
|
2008-11-17 13:34:03 -07:00
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
/*
|
2008-10-26 09:27:50 -06:00
|
|
|
Raw formatter. See print.go for a more palatable interface.
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
f := fmt.New();
|
|
|
|
print f.d(1234).s("\n").str(); // create string, print it
|
|
|
|
f.d(-1234).s("\n").put(); // print string
|
2008-10-26 09:27:50 -06:00
|
|
|
f.ud(1<<63).putnl(); // print string with automatic newline
|
2008-03-27 01:06:21 -06:00
|
|
|
*/
|
|
|
|
|
2008-08-09 15:50:29 -06:00
|
|
|
// export Fmt, New;
|
2008-03-27 01:06:21 -06:00
|
|
|
|
2008-07-08 15:20:04 -06:00
|
|
|
const NByte = 64;
|
2008-07-23 21:02:54 -06:00
|
|
|
const NPows10 = 160;
|
2008-07-08 15:20:04 -06:00
|
|
|
|
2008-08-09 15:50:29 -06:00
|
|
|
var ldigits string = "0123456789abcdef" // var not const because we take its address
|
|
|
|
var udigits string = "0123456789ABCDEF"
|
2008-10-29 14:09:39 -06:00
|
|
|
var pows10 [NPows10] float64;
|
2008-03-27 01:06:21 -06:00
|
|
|
|
2008-07-19 15:52:01 -06:00
|
|
|
func init() {
|
|
|
|
pows10[0] = 1.0e0;
|
|
|
|
pows10[1] = 1.0e1;
|
|
|
|
for i:=2; i<NPows10; i++ {
|
|
|
|
m := i/2;
|
|
|
|
pows10[i] = pows10[m] * pows10[i-m];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-04 18:17:59 -06:00
|
|
|
export type Fmt struct {
|
2008-03-27 01:06:21 -06:00
|
|
|
buf string;
|
|
|
|
wid int;
|
|
|
|
wid_present bool;
|
|
|
|
prec int;
|
|
|
|
prec_present bool;
|
2008-11-24 15:51:33 -07:00
|
|
|
// flags
|
|
|
|
minus bool;
|
|
|
|
plus bool;
|
|
|
|
sharp bool;
|
|
|
|
space bool;
|
|
|
|
zero bool;
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) clearflags() {
|
|
|
|
f.wid_present = false;
|
|
|
|
f.prec_present = false;
|
2008-11-24 15:51:33 -07:00
|
|
|
f.minus = false;
|
|
|
|
f.plus = false;
|
|
|
|
f.sharp = false;
|
|
|
|
f.space = false;
|
|
|
|
f.zero = false;
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) clearbuf() {
|
|
|
|
f.buf = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) init() {
|
|
|
|
f.clearbuf();
|
|
|
|
f.clearflags();
|
|
|
|
}
|
|
|
|
|
2008-08-04 18:17:59 -06:00
|
|
|
export func New() *Fmt {
|
2008-03-27 01:06:21 -06:00
|
|
|
f := new(Fmt);
|
|
|
|
f.init();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) str() string {
|
|
|
|
s := f.buf;
|
|
|
|
f.clearbuf();
|
|
|
|
f.clearflags();
|
|
|
|
f.buf = "";
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) put() {
|
2008-08-11 22:37:46 -06:00
|
|
|
print(f.buf);
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearbuf();
|
|
|
|
f.clearflags();
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) putnl() {
|
2008-08-11 22:37:46 -06:00
|
|
|
print(f.buf, "\n");
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearbuf();
|
|
|
|
f.clearflags();
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) wp(w, p int) *Fmt {
|
|
|
|
f.wid_present = true;
|
|
|
|
f.wid = w;
|
|
|
|
f.prec_present = true;
|
|
|
|
f.prec = p;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) p(p int) *Fmt {
|
|
|
|
f.prec_present = true;
|
|
|
|
f.prec = p;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) w(x int) *Fmt {
|
|
|
|
f.wid_present = true;
|
|
|
|
f.wid = x;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-11-24 15:51:33 -07:00
|
|
|
// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus)
|
2008-03-27 01:06:21 -06:00
|
|
|
// 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 {
|
2008-11-24 15:51:33 -07:00
|
|
|
left := !f.minus;
|
2008-03-27 01:06:21 -06:00
|
|
|
w := f.wid;
|
|
|
|
if w < 0 {
|
|
|
|
left = false;
|
|
|
|
w = -w;
|
|
|
|
}
|
|
|
|
w -= len(s);
|
2008-11-24 15:51:33 -07:00
|
|
|
padchar := byte(' ');
|
|
|
|
if left && f.zero {
|
|
|
|
padchar = '0';
|
|
|
|
}
|
2008-03-27 01:06:21 -06:00
|
|
|
if w > 0 {
|
2008-07-08 15:20:04 -06:00
|
|
|
if w > NByte {
|
|
|
|
w = NByte;
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
2008-09-04 11:39:04 -06:00
|
|
|
buf := new([]byte, w);
|
2008-03-27 01:06:21 -06:00
|
|
|
for i := 0; i < w; i++ {
|
2008-11-24 15:51:33 -07:00
|
|
|
buf[i] = padchar;
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
if left {
|
2008-09-04 11:39:04 -06:00
|
|
|
s = string(buf) + s;
|
2008-03-27 01:06:21 -06:00
|
|
|
} else {
|
2008-09-04 11:39:04 -06:00
|
|
|
s = s + string(buf);
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-27 12:36:40 -06:00
|
|
|
f.buf += s;
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// format val into buf, ending at buf[i]. (printing is easier right-to-left;
|
|
|
|
// that's why the bidi languages are right-to-left except for numbers. wait,
|
|
|
|
// never mind.) val is known to be unsigned. we could make things maybe
|
|
|
|
// marginally faster by splitting the 32-bit case out into a separate function
|
|
|
|
// but it's not worth the duplication, so val has 64 bits.
|
2008-07-08 15:20:04 -06:00
|
|
|
func putint(buf *[NByte]byte, i int, base, val uint64, digits *string) int {
|
2008-03-27 01:06:21 -06:00
|
|
|
for val >= base {
|
2008-07-08 15:20:04 -06:00
|
|
|
buf[i] = digits[val%base];
|
2008-03-27 01:06:21 -06:00
|
|
|
i--;
|
|
|
|
val /= base;
|
|
|
|
}
|
2008-07-08 15:20:04 -06:00
|
|
|
buf[i] = digits[val];
|
2008-03-27 01:06:21 -06:00
|
|
|
return i-1;
|
|
|
|
}
|
|
|
|
|
2008-06-24 13:54:26 -06:00
|
|
|
// boolean
|
|
|
|
func (f *Fmt) boolean(a bool) *Fmt {
|
|
|
|
if a {
|
|
|
|
f.pad("true");
|
|
|
|
} else {
|
|
|
|
f.pad("false");
|
|
|
|
}
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
// integer; interprets prec but not wid.
|
2008-04-02 22:32:39 -06:00
|
|
|
func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string {
|
2008-07-08 15:20:04 -06:00
|
|
|
var buf [NByte]byte;
|
2008-03-27 01:06:21 -06:00
|
|
|
negative := is_signed && a < 0;
|
|
|
|
if negative {
|
|
|
|
a = -a;
|
|
|
|
}
|
2008-11-24 15:51:33 -07:00
|
|
|
|
|
|
|
// two ways to ask for extra leading zero digits: %.3d or %03d.
|
|
|
|
// apparently the first cancels the second.
|
|
|
|
prec := 0;
|
2008-03-27 01:06:21 -06:00
|
|
|
if f.prec_present {
|
2008-11-24 15:51:33 -07:00
|
|
|
prec = f.prec;
|
|
|
|
f.zero = false;
|
|
|
|
} else if f.zero && f.wid_present && !f.minus && f.wid > 0{
|
|
|
|
prec = f.wid;
|
|
|
|
if negative || f.plus || f.space {
|
|
|
|
prec--; // leave room for sign
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 15:51:33 -07:00
|
|
|
|
|
|
|
i := putint(&buf, NByte-1, uint64(base), uint64(a), digits);
|
|
|
|
for i > 0 && prec > (NByte-1-i) {
|
|
|
|
buf[i] = '0';
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
if negative {
|
|
|
|
buf[i] = '-';
|
|
|
|
i--;
|
2008-11-24 15:51:33 -07:00
|
|
|
} else if f.plus {
|
|
|
|
buf[i] = '+';
|
|
|
|
i--;
|
|
|
|
} else if f.space {
|
|
|
|
buf[i] = ' ';
|
|
|
|
i--;
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
2008-07-08 15:20:04 -06:00
|
|
|
return string(buf)[i+1:NByte];
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// decimal
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) d64(a int64) *Fmt {
|
|
|
|
f.pad(f.integer(a, 10, true, &ldigits));
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
2008-11-17 13:34:03 -07:00
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) d32(a int32) *Fmt {
|
|
|
|
return f.d64(int64(a));
|
|
|
|
}
|
2008-03-27 01:06:21 -06:00
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) d(a int) *Fmt {
|
|
|
|
return f.d64(int64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// unsigned decimal
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) ud64(a uint64) *Fmt {
|
|
|
|
f.pad(f.integer(int64(a), 10, false, &ldigits));
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) ud32(a uint32) *Fmt {
|
|
|
|
return f.ud64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) ud(a uint) *Fmt {
|
|
|
|
return f.ud64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
// hexdecimal
|
|
|
|
func (f *Fmt) x64(a int64) *Fmt {
|
2008-03-27 01:06:21 -06:00
|
|
|
f.pad(f.integer(a, 16, true, &ldigits));
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) x32(a int32) *Fmt {
|
|
|
|
return f.x64(int64(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) x(a int) *Fmt {
|
|
|
|
return f.x64(int64(a));
|
|
|
|
}
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
// unsigned hexdecimal
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) ux64(a uint64) *Fmt {
|
|
|
|
f.pad(f.integer(int64(a), 16, false, &ldigits));
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) ux32(a uint32) *Fmt {
|
|
|
|
return f.ux64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) ux(a uint) *Fmt {
|
|
|
|
return f.ux64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
// HEXADECIMAL
|
|
|
|
func (f *Fmt) X64(a int64) *Fmt {
|
2008-03-27 01:06:21 -06:00
|
|
|
f.pad(f.integer(a, 16, true, &udigits));
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) X32(a int32) *Fmt {
|
|
|
|
return f.X64(int64(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) X(a int) *Fmt {
|
|
|
|
return f.X64(int64(a));
|
|
|
|
}
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
// unsigned HEXADECIMAL
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) uX64(a uint64) *Fmt {
|
|
|
|
f.pad(f.integer(int64(a), 16, false, &udigits));
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) uX32(a uint32) *Fmt {
|
|
|
|
return f.uX64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) uX(a uint) *Fmt {
|
|
|
|
return f.uX64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
// octal
|
|
|
|
func (f *Fmt) o64(a int64) *Fmt {
|
2008-03-27 01:06:21 -06:00
|
|
|
f.pad(f.integer(a, 8, true, &ldigits));
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) o32(a int32) *Fmt {
|
|
|
|
return f.o64(int64(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) o(a int) *Fmt {
|
|
|
|
return f.o64(int64(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
// unsigned octal
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) uo64(a uint64) *Fmt {
|
|
|
|
f.pad(f.integer(int64(a), 8, false, &ldigits));
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) uo32(a uint32) *Fmt {
|
|
|
|
return f.uo64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) uo(a uint) *Fmt {
|
|
|
|
return f.uo64(uint64(a));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
|
|
|
|
// unsigned binary
|
|
|
|
func (f *Fmt) b64(a uint64) *Fmt {
|
|
|
|
f.pad(f.integer(int64(a), 2, false, &ldigits));
|
2008-03-27 01:06:21 -06:00
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) b32(a uint32) *Fmt {
|
|
|
|
return f.b64(uint64(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) b(a uint) *Fmt {
|
|
|
|
return f.b64(uint64(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
// character
|
|
|
|
func (f *Fmt) c(a int) *Fmt {
|
|
|
|
f.pad(string(a));
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// string
|
|
|
|
func (f *Fmt) s(s string) *Fmt {
|
|
|
|
if f.prec_present {
|
|
|
|
if f.prec < len(s) {
|
2008-04-02 22:32:39 -06:00
|
|
|
s = s[0:f.prec];
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
f.pad(s);
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-11-24 15:51:33 -07:00
|
|
|
// hexadecimal string
|
|
|
|
func (f *Fmt) sx(s string) *Fmt {
|
|
|
|
t := "";
|
|
|
|
for i := 0; i < len(s); i++ {
|
2008-11-25 10:23:13 -07:00
|
|
|
if i > 0 && f.space {
|
|
|
|
t += " ";
|
|
|
|
}
|
2008-11-24 15:51:33 -07:00
|
|
|
v := s[i];
|
|
|
|
t += string(ldigits[v>>4]);
|
|
|
|
t += string(ldigits[v&0xF]);
|
|
|
|
}
|
|
|
|
f.pad(t);
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) sX(s string) *Fmt {
|
|
|
|
t := "";
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
v := s[i];
|
|
|
|
t += string(udigits[v>>4]);
|
|
|
|
t += string(udigits[v&0xF]);
|
|
|
|
}
|
|
|
|
f.pad(t);
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// quoted string
|
|
|
|
func (f *Fmt) q(s string) *Fmt {
|
|
|
|
var quoted string;
|
|
|
|
if f.sharp && strconv.CanBackquote(s) {
|
|
|
|
quoted = "`"+s+"`";
|
|
|
|
} else {
|
|
|
|
quoted = strconv.Quote(s);
|
|
|
|
}
|
|
|
|
f.pad(quoted);
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
// floating-point
|
2008-03-27 01:06:21 -06:00
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
func Prec(f *Fmt, def int) int {
|
|
|
|
if f.prec_present {
|
|
|
|
return f.prec;
|
2008-08-11 16:04:54 -06:00
|
|
|
}
|
2008-11-17 13:34:03 -07:00
|
|
|
return def;
|
2008-08-11 16:04:54 -06:00
|
|
|
}
|
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
func FmtString(f *Fmt, s string) *Fmt {
|
2008-03-27 01:06:21 -06:00
|
|
|
f.pad(s);
|
|
|
|
f.clearflags();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:09:39 -06:00
|
|
|
// float64
|
2008-11-17 13:34:03 -07:00
|
|
|
func (f *Fmt) e64(a float64) *Fmt {
|
|
|
|
return FmtString(f, strconv.ftoa64(a, 'e', Prec(f, 6)));
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) f64(a float64) *Fmt {
|
2008-11-17 13:34:03 -07:00
|
|
|
return FmtString(f, strconv.ftoa64(a, 'f', Prec(f, 6)));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-10-29 15:28:19 -06:00
|
|
|
func (f *Fmt) g64(a float64) *Fmt {
|
2008-11-17 13:34:03 -07:00
|
|
|
return FmtString(f, strconv.ftoa64(a, 'g', Prec(f, -1)));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
func (f *Fmt) fb64(a float64) *Fmt {
|
|
|
|
return FmtString(f, strconv.ftoa64(a, 'b', 0));
|
2008-10-29 15:28:19 -06:00
|
|
|
}
|
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
// float32
|
|
|
|
// cannot defer to float64 versions
|
|
|
|
// because it will get rounding wrong in corner cases.
|
|
|
|
func (f *Fmt) e32(a float32) *Fmt {
|
2008-11-24 15:51:33 -07:00
|
|
|
return FmtString(f, strconv.ftoa32(a, 'e', Prec(f, 6)));
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) f32(a float32) *Fmt {
|
|
|
|
return FmtString(f, strconv.ftoa32(a, 'f', Prec(f, 6)));
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) g32(a float32) *Fmt {
|
|
|
|
return FmtString(f, strconv.ftoa32(a, 'g', Prec(f, -1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fmt) fb32(a float32) *Fmt {
|
|
|
|
return FmtString(f, strconv.ftoa32(a, 'b', 0));
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// float
|
2008-11-17 13:34:03 -07:00
|
|
|
func (x *Fmt) f(a float) *Fmt {
|
|
|
|
if strconv.floatsize == 32 {
|
|
|
|
return x.f32(float32(a))
|
|
|
|
}
|
|
|
|
return x.f64(float64(a))
|
2008-10-29 15:28:19 -06:00
|
|
|
}
|
|
|
|
|
2008-03-27 01:06:21 -06:00
|
|
|
func (x *Fmt) e(a float) *Fmt {
|
2008-11-17 13:34:03 -07:00
|
|
|
if strconv.floatsize == 32 {
|
|
|
|
return x.e32(float32(a))
|
|
|
|
}
|
2008-10-29 15:28:19 -06:00
|
|
|
return x.e64(float64(a))
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
func (x *Fmt) g(a float) *Fmt {
|
|
|
|
if strconv.floatsize == 32 {
|
|
|
|
return x.g32(float32(a))
|
|
|
|
}
|
2008-10-29 15:28:19 -06:00
|
|
|
return x.g64(float64(a))
|
|
|
|
}
|
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
func (x *Fmt) fb(a float) *Fmt {
|
|
|
|
if strconv.floatsize == 32 {
|
|
|
|
return x.fb32(float32(a))
|
|
|
|
}
|
|
|
|
return x.fb64(float64(a))
|
2008-03-27 01:06:21 -06:00
|
|
|
}
|