Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: incorrect handling of f.space in combination with f.plus #14543

Closed
martisch opened this issue Feb 27, 2016 · 2 comments
Closed

fmt: incorrect handling of f.space in combination with f.plus #14543

martisch opened this issue Feb 27, 2016 · 2 comments

Comments

@martisch
Copy link
Contributor

@martisch martisch commented Feb 27, 2016

This problem exists at least in current, go1.6, go1.4:

"% +verb" is inconsistently handled between different verbs.

http://play.golang.org/p/K7z4LPRrop

outputs:

 1
+1
+1
+1
+1
+1
+U+0001
( 4503599627370496p-52+4503599627370496p-52i)
( 1.000000e+00+1.000000e+00i)
( 1.000000E+00+1.000000E+00i)
( 1.000000+1.000000i)
( 1.000000+1.000000i)
( 1+1i)
( 1+1i)
 4503599627370496p-52
 1.000000e+00
 1.000000E+00
 1.000000
 1.000000
 1
 1

I would expect a + in front of every number if f.plus is specified (compatible with c printf).
Except i am unsure how and if f.plus and f.space should be applied to %U.

I will work on a patch and test cases to correct this.

@martisch
Copy link
Contributor Author

@martisch martisch commented Feb 27, 2016

"% +v" seems also special. the f.space is applied to numbers but f.plus (due to being used for struct names) is not applied to number. Since it says %v prints in default format maybe f.space should not do anything here.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 27, 2016

CL https://golang.org/cl/19974 mentions this issue.

gopherbot pushed a commit that referenced this issue Feb 29, 2016
Do not replace the sign in front of a number with a space if both
f.space and f.plus are both specified for number formatting.
This was already the case for integers but not for floats
and complex numbers.

Updates: #14543.

Change-Id: I07ddeb505003db84a8a7d2c743dc19fc427a00bd
Reviewed-on: https://go-review.googlesource.com/19974
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
@martisch martisch closed this Mar 11, 2016
@golang golang locked and limited conversation to collaborators Mar 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.