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: bad formatting of complex numbers with %f #8064

Closed
jscrockett01 opened this issue May 21, 2014 · 5 comments
Closed

fmt: bad formatting of complex numbers with %f #8064

jscrockett01 opened this issue May 21, 2014 · 5 comments
Milestone

Comments

@jscrockett01
Copy link

Complex numbers are handled erratically by printf %f verb when using zero padding or
space padding.  Examples of both are on the playground here:

http://play.golang.org/p/9_nUdI3fgd

As of today the playground (go1.2rc3) prints the space padding correctly but the zero
padding incorrectly.  However, on my machine (go1.3beta2 windows/amd64) both the space
and zero are incorrect, so there has been a regression with respect to the space
padding.  My machine output is shown below.

Some related CLs:
https://golang.org/cl/12498043/
https://golang.org/cl/35660043/

misplaced space-vs-sign issue:
(+ 104.66+440.51i)
(+ 164.56 -62.29i)
(  -75.36+ 186.82i)
( -434.36 -343.48i)
( -403.03 -199.09i)
(+  15.21+313.64i)
( -285.74 -119.34i)
( -181.94  -31.11i)

misplaced zero-vs-sign issue:
(0-216.970-206.90i)
(+0179.08-281.45i)
(0-296.810-139.13i)
(+0070.67+362.49i)
(0-206.890-202.92i)
(+0252.57-293.42i)
(+0365.34+196.72i)
(+0023.82-471.70i)
@jscrockett01
Copy link
Author

Comment 1:

Notice also that whenever the real part is negative the width count is off by one so the
output is wider by 1 char (for both space & zero issues).

@bradfitz
Copy link
Contributor

Comment 2:

To Rob for triage.

Labels changed: added release-go1.3maybe, repo-main.

Owner changed to @robpike.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented May 21, 2014

Comment 3:

It's a regression. Will fix for 1.3

Labels changed: added release-go1.3, removed release-go1.3maybe.

@gopherbot
Copy link

Comment 4:

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

@robpike
Copy link
Contributor

robpike commented May 21, 2014

Comment 5:

This issue was closed by revision 4464ae2.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
Rewrite formatFloat to be much simpler and clearer and
avoid the tricky interaction with padding.
The issue refers to complex but the problem is just floating-point.
The new tests added were incorrectly formatted before this fix.
Fixes golang#8064.

LGTM=jscrockett01, rsc
R=rsc, jscrockett01
CC=golang-codereviews
https://golang.org/cl/99420048
@rsc rsc unassigned robpike Jun 23, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants