Navigation Menu

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
Milestone

Comments

@martisch
Copy link
Contributor

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 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 commented Feb 20, 2016 via email

@martisch
Copy link
Contributor Author

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

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

@golang golang locked and limited conversation to collaborators Feb 28, 2017
@rsc rsc unassigned robpike Jun 23, 2022
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