Skip to content

Commit

Permalink
Rollup merge of rust-lang#89502 - FabianWolff:issue-89493, r=joshtrip…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Manishearth authored Oct 5, 2021
2 parents 0f3c2df + 199b33f commit 55ea391
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ macro_rules! impl_Exp {
n /= 10;
exponent += 1;
}
let trailing_zeros = exponent;

let (added_precision, subtracted_precision) = match f.precision() {
Some(fmt_prec) => {
Expand Down Expand Up @@ -333,7 +332,7 @@ macro_rules! impl_Exp {
n += 1;
}
}
(n, exponent, trailing_zeros, added_precision)
(n, exponent, exponent, added_precision)
};

// 39 digits (worst case u128) + . = 40
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fn test_format_int_exp_precision() {
assert_eq!(format!("{:.1000e}", 1), format!("1.{}e0", "0".repeat(1000)));
//test zero precision
assert_eq!(format!("{:.0e}", 1), format!("1e0",));
assert_eq!(format!("{:.0e}", 35), format!("4e1",));

//test padding with precision (and sign)
assert_eq!(format!("{:+10.3e}", 1), " +1.000e0");
Expand Down

0 comments on commit 55ea391

Please sign in to comment.