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

fix confusion about parts required for float formatting #41859

Merged
merged 1 commit into from
May 15, 2017

Conversation

froydnj
Copy link
Contributor

@froydnj froydnj commented May 9, 2017

The documentation for flt2dec doesn't match up with the actual
implementation, so fix the documentation to align with reality.
Presumably due to the mismatch, the formatting code for floats in
std::fmt can use correspondingly shorter arrays in some places, so fix
those places up as well.

Fixes #41304.

The documentation for flt2dec doesn't match up with the actual
implementation, so fix the documentation to align with reality.
Presumably due to the mismatch, the formatting code for floats in
std::fmt can use correspondingly shorter arrays in some places, so fix
those places up as well.

Fixes rust-lang#41304.
@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

/// There should be at least 5 parts available, due to the worst case like
/// `[+][0.][0000][45][0000]` with `frac_digits = 10`.
/// There should be at least 4 parts available, due to the worst case like
/// `[+][0.][0000][2][0000]` with `frac_digits = 10`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? I still count 5 parts +, 0., 0000, 2 and 0000.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that the [] notation is being used in two ways here: to denote a Part and to--I think--indicate the optional quality of the sign of the formatted number. Since the [+] is being used in the latter sense, it does not count as a Part that would be stored in the parts array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, perhaps the + should use a different bracket or no brackets, or just omit the + altogether. Also, why the 45 is changed to 2? That doesn't seem to make any difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the use of the numbers here was that they were denoting the index of the associated Part in the parts array. So the 45 shouldn't be understood as the number "45", but parts[4] and parts[5]. (Which is not correct in the first place, I believe.) You can see this notation on display a little more clearly in to_shortest_exp_str, where we have [+][1][.][2345][e][-][6] as a result of this patch, though note that 1-based indexing is being used here rather than 0-based... I changed 45 to 2 following said understanding, as the non-zero numbers there would be parts[2].

I agree that this is not the best notation for explaining things! Perhaps a separate pull request would be appropriate to make the documentation a little clearer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… I think you are overthinking about this 😄 When the documentation was originally written, the + sign is indeed a part, so [+][1][.][2345][e][-][67] had 7 parts because there are 7 []s, not due to 1234567. Later the + sign is no longer a part but the documentation failed to catch up until this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, indeed! :)

@TimNN TimNN added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 10, 2017
@TimNN
Copy link
Contributor

TimNN commented May 10, 2017

Hi @froydnj, thanks for the PR! We'll periodically check in on it to make sure that @sfackler or someone else from the team reviews it soon.

@Mark-Simulacrum
Copy link
Member

@sfackler Could you take a look at the changes here? You're assigned.

cc @BurntSushi

@sfackler
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 14, 2017

📌 Commit b185844 has been approved by sfackler

@bors
Copy link
Contributor

bors commented May 14, 2017

⌛ Testing commit b185844 with merge 788c960...

@bors
Copy link
Contributor

bors commented May 14, 2017

💔 Test failed - status-appveyor

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 14, 2017
fix confusion about parts required for float formatting

The documentation for flt2dec doesn't match up with the actual
implementation, so fix the documentation to align with reality.
Presumably due to the mismatch, the formatting code for floats in
std::fmt can use correspondingly shorter arrays in some places, so fix
those places up as well.

Fixes rust-lang#41304.
@bors
Copy link
Contributor

bors commented May 15, 2017

⌛ Testing commit b185844 with merge ac254fb...

bors added a commit that referenced this pull request May 15, 2017
fix confusion about parts required for float formatting

The documentation for flt2dec doesn't match up with the actual
implementation, so fix the documentation to align with reality.
Presumably due to the mismatch, the formatting code for floats in
std::fmt can use correspondingly shorter arrays in some places, so fix
those places up as well.

Fixes #41304.
@bors
Copy link
Contributor

bors commented May 15, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: sfackler
Pushing ac254fb to master...

@bors bors merged commit b185844 into rust-lang:master May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flt2dec comments and code disagree about the numbers of parts required for formatting
7 participants