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 · 3 comments
Open

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

rogpeppe opened this issue Nov 30, 2020 · 3 comments

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

Loading

@griesemer griesemer removed this from the Backlog milestone Dec 5, 2020
@griesemer griesemer added this to the Go1.17 milestone Dec 5, 2020
@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented May 21, 2021

@griesemer Do you expect you'll have time to investigate and fix this for Go 1.17? We're three weeks into the freeze now and it doesn't seem someone is working on this, so I'll tentatively move this to Backlog, but please feel free to move it back otherwise.

Loading

@dmitshur dmitshur removed this from the Go1.17 milestone May 21, 2021
@dmitshur dmitshur added this to the Backlog milestone May 21, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 17, 2021

Probably not hard to fix but will take some time to ensure we're not breaking something else. Won't get to this for 1.17 due to higher priority items.

Loading

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
4 participants