Commit 5ad5b7a5 authored by Felix Geisendörfer's avatar Felix Geisendörfer Committed by Rob Pike

fmt: Fix signed zero-padding for positive floats

Space padding still has the same issue, I will send a separate patch for that
if this one gets accepted.
Fixes #6856.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/35660043
parent 1d08fc44
...@@ -220,6 +220,8 @@ var fmtTests = []struct { ...@@ -220,6 +220,8 @@ var fmtTests = []struct {
{"%+.3e", 0.0, "+0.000e+00"}, {"%+.3e", 0.0, "+0.000e+00"},
{"%+.3e", 1.0, "+1.000e+00"}, {"%+.3e", 1.0, "+1.000e+00"},
{"%+.3f", -1.0, "-1.000"}, {"%+.3f", -1.0, "-1.000"},
{"%+07.2f", 1.0, "+001.00"},
{"%+07.2f", -1.0, "-001.00"},
{"% .3E", -1.0, "-1.000E+00"}, {"% .3E", -1.0, "-1.000E+00"},
{"% .3e", 1.0, " 1.000e+00"}, {"% .3e", 1.0, " 1.000e+00"},
{"%+.3g", 0.0, "+0"}, {"%+.3g", 0.0, "+0"},
......
...@@ -372,7 +372,10 @@ func (f *fmt) formatFloat(v float64, verb byte, prec, n int) { ...@@ -372,7 +372,10 @@ func (f *fmt) formatFloat(v float64, verb byte, prec, n int) {
default: default:
// There's no sign, but we might need one. // There's no sign, but we might need one.
if f.plus { if f.plus {
slice[0] = '+' f.buf.WriteByte('+')
f.wid--
f.pad(slice[1:])
return
} else if f.space { } else if f.space {
// space is already there // space is already there
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment