]> Cypherpunks repositories - gostls13.git/commit
fmt: refactor and unify float and complex formatting
authorMartin Möhrmann <martisch@uos.de>
Sat, 27 Feb 2016 13:37:10 +0000 (14:37 +0100)
committerRob Pike <r@golang.org>
Sun, 6 Mar 2016 02:18:05 +0000 (02:18 +0000)
commitbd6d84282a441a35b4629eaa958d3ce24d396a6f
treeda6356cbc6b10c793edf5f660469c73675c03a19
parent5763476f739ad4d6b122c2a7ae26a845ea020a7e
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>
src/fmt/fmt_test.go
src/fmt/format.go
src/fmt/print.go