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

Lower/UpperExp inconsistent between integers and floats #89493

Closed
nrabulinski opened this issue Oct 3, 2021 · 3 comments
Closed

Lower/UpperExp inconsistent between integers and floats #89493

nrabulinski opened this issue Oct 3, 2021 · 3 comments
Labels
A-fmt Area: `std::fmt` C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@nrabulinski
Copy link
Contributor

nrabulinski commented Oct 3, 2021

I tried this code:

println!("{:.*e}", 0, 25);
println!("{:.*e}", 0, 25.0);

I expected to see this happen:
The output should be the same regardless if I'm formatting an integer or a float, in this case most likely 3e1.

Instead, this happened:

3.e1
2e1

Happens in both latest stable and nightly.

EDIT: I'm suspecting this is actually two separate bugs in both the integer and float implementation - the integer result contains a . which should not be there, and the float gets rounded down to 2 despite 25.1 rounding to 3e1 - which is the result I would expect for 25.0 as well.

@joshtriplett
Copy link
Member

For the floating-point portion of this, I think the default is "round to nearest even", which would make 2e1 the correct rounding.

It seems odd that integers and floating-point values have different rounding here.

@nrabulinski
Copy link
Contributor Author

For the floating-point portion of this, I think the default is "round to nearest even", which would make 2e1 the correct rounding.

It seems odd that integers and floating-point values have different rounding here.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a056ffde1e5a237e2e26351615775809

Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…lett

Fix Lower/UpperExp formatting for integers and precision zero

Fixes the integer part of rust-lang#89493 (I daren't touch the floating-point formatting code). The issue is that the "subtracted" precision essentially behaves like extra trailing zeros, but this is not currently reflected in the code properly.
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…lett

Fix Lower/UpperExp formatting for integers and precision zero

Fixes the integer part of rust-lang#89493 (I daren't touch the floating-point formatting code). The issue is that the "subtracted" precision essentially behaves like extra trailing zeros, but this is not currently reflected in the code properly.
@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@fmease fmease added T-libs Relevant to the library team, which will review and decide on the PR/issue. A-fmt Area: `std::fmt` and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Jan 24, 2024
@fmease
Copy link
Member

fmease commented Jan 24, 2024

I can no longer reproduce this on the latest nightly (1.77, 2024-01-22 d5fd099), I get:

2e1
2e1

Interestingly, stable (1.75) produces the following which still contains the rounding error:

3e1
2e1

Closing as completed. Please ping me if I should reopen this issue.

@fmease fmease closed this as completed Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fmt Area: `std::fmt` C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants