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

math/big: Float.String inconsistent with format %v #42887

Open
rogpeppe opened this issue Nov 30, 2020 · 1 comment
Open

math/big: Float.String inconsistent with format %v #42887

rogpeppe opened this issue Nov 30, 2020 · 1 comment
Milestone

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Nov 30, 2020

go version devel +926994fd7c Thu Nov 26 21:10:09 2020 +0000 linux/amd64

I was surprised today when I discovered that big.Float.String truncates to 10 decimal digits of precision, which is surely not a very useful default for a "big" float. I would expect the result to use as many digits of precision as necessary, as if it was using Float.Text('g', -1).

Another remark: most types that implement fmt.Stringer work with the %s verb. Perhaps big.Float could do that too, making %s equivalent to %v.

The following code prints three different things. I'd expect it to print the same thing three times:

x := big.NewFloat(4.2949672961e+09)

fmt.Printf("%v\n", x)
fmt.Printf("%s\n", x.String())
fmt.Printf("%s\n", x)
@cagedmantis cagedmantis added this to the Backlog milestone Dec 4, 2020
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Dec 4, 2020

@griesemer griesemer modified the milestones: Backlog, Go1.17 Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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