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

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
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rogpeppe
Copy link
Contributor

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 4, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Dec 4, 2020
@cagedmantis
Copy link
Contributor

/cc @griesemer @FiloSottile

@griesemer griesemer modified the milestones: Backlog, Go1.17 Dec 5, 2020
@dmitshur
Copy link
Contributor

@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.

@dmitshur dmitshur modified the milestones: Go1.17, Backlog May 21, 2021
@griesemer
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants