Skip to content

Commit 55ea391

Browse files
authored
Rollup merge of rust-lang#89502 - FabianWolff:issue-89493, r=joshtriplett
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.
2 parents 0f3c2df + 199b33f commit 55ea391

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/fmt/num.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ macro_rules! impl_Exp {
305305
n /= 10;
306306
exponent += 1;
307307
}
308-
let trailing_zeros = exponent;
309308

310309
let (added_precision, subtracted_precision) = match f.precision() {
311310
Some(fmt_prec) => {
@@ -333,7 +332,7 @@ macro_rules! impl_Exp {
333332
n += 1;
334333
}
335334
}
336-
(n, exponent, trailing_zeros, added_precision)
335+
(n, exponent, exponent, added_precision)
337336
};
338337

339338
// 39 digits (worst case u128) + . = 40

library/core/tests/fmt/num.rs

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn test_format_int_exp_precision() {
146146
assert_eq!(format!("{:.1000e}", 1), format!("1.{}e0", "0".repeat(1000)));
147147
//test zero precision
148148
assert_eq!(format!("{:.0e}", 1), format!("1e0",));
149+
assert_eq!(format!("{:.0e}", 35), format!("4e1",));
149150

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

0 commit comments

Comments
 (0)