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: inconsistency in 0 padded formatting of Inf and Nan float values #14421

Closed
martisch opened this issue Feb 20, 2016 · 4 comments
Closed

fmt: inconsistency in 0 padded formatting of Inf and Nan float values #14421

martisch opened this issue Feb 20, 2016 · 4 comments
Assignees
Milestone

Comments

@martisch
Copy link
Contributor

@martisch martisch commented Feb 20, 2016

For e.g. "%020f" Inf is not 0 padded but NaN is.

00000000000000000NaN
                +Inf
                -Inf


https://play.golang.org/p/qiO-mme4S6

There is no test case for 0 padded NaN (but for Inf) and it seems this behavior has existed throughout Go 1.x .
C does not 0 pad NaN and Infs which seemed the reason the Infs are treated special in Go too.

This might not be changed anymore due to the Go 1 guarantees but the API documentation does not seem to explicitly mention the treatment for NaN or Inf either.

Not sure if it should just be document or if this should be fixed for 1.7 
If ok i can submit a patch that just adds a test case for current Go behavior with a comment that references this issue or make the treatment of NaN consistent with Inf.
@robpike
Copy link
Contributor

@robpike robpike commented Feb 20, 2016

It's just saying, "Oooooh, a Nan!".

Might be a consequence of https://go-review.googlesource.com/19721 or might be old. Should be easy to fix regardless.

@minux
Copy link
Member

@minux minux commented Feb 20, 2016

@martisch
Copy link
Contributor Author

@martisch martisch commented Feb 21, 2016

Writing the patch that rob mentioned made me aware of the NaN case.
I write a patch to fix the NaN case now.
Just wanted to make sure its ok to correct and does not break any Go 1.x guarantees. But since Inf only changed in 1.3 i guess its ok to make them consistent.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 21, 2016

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

@gopherbot gopherbot closed this in 5dc053b Feb 21, 2016
@golang golang locked and limited conversation to collaborators Feb 28, 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
5 participants
You can’t perform that action at this time.