1
0
mirror of https://github.com/golang/go synced 2024-10-05 09:21:22 -06:00
go/src/fmt
Martin Möhrmann bd6d84282a fmt: refactor and unify float and complex formatting
Removes specialized functions for each verb and float/complex size
and replaces them with generic variants fmtFloat and
fmtComplex similar to other generic fmt functions.

Simplifies the complex formatting by relying on fmtFloat
to handle the verb and default precision selection.

Complex imaginary formatting does not need to clear the f.space flag
because the set f.plus flag will force a sign instead of a space.

Sets default precision for %b to -1 (same as %g and %G)
since precision for %b has no affect in strconv.AppendFloat.

Add more tests and group them a bit better.
Use local copies of +Inf,-Inf and NaN instead
of math package functions for testing.

Saves around 8kb in the go binary.

name              old time/op  new time/op  delta
SprintfFloat-2     200ns ± 4%   196ns ± 4%  -1.55%  (p=0.007 n=20+20)
SprintfComplex-2   569ns ± 4%   570ns ± 3%    ~     (p=0.804 n=20+20)

Change-Id: I36d35dab6f835fc2bd2c042ac97705868eb2446f
Reviewed-on: https://go-review.googlesource.com/20252
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
2016-03-06 02:18:05 +00:00
..
doc.go fmt: clarify reflect.Value printing 2015-10-19 18:29:36 +00:00
export_test.go all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
fmt_test.go fmt: refactor and unify float and complex formatting 2016-03-06 02:18:05 +00:00
format.go fmt: refactor and unify float and complex formatting 2016-03-06 02:18:05 +00:00
print.go fmt: refactor and unify float and complex formatting 2016-03-06 02:18:05 +00:00
scan_test.go all: single space after period. 2016-03-02 00:13:47 +00:00
scan.go all: single space after period. 2016-03-02 00:13:47 +00:00
stringer_test.go