Skip to content

Commit 58b768f

Browse files
authored
Unrolled build for #142114
Rollup merge of #142114 - GuillaumeGomez:u128-const, r=Urgau Compute number of digits instead of relying on constant value for u128 display code As discussed in https://github.com/rust-lang/rust/pull/142098/files#r2132084991, the code should reuse the same logic as the rest of file instead of using a constant value. r? `@tamird`
2 parents 868bf2d + 28a2e1e commit 58b768f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/core/src/fmt/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ impl fmt::Display for i128 {
678678
/// It also has to handle 1 last item, as 10^40 > 2^128 > 10^39, whereas
679679
/// 10^20 > 2^64 > 10^19.
680680
fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
681-
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
682-
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
681+
const MAX_DEC_N: usize = u128::MAX.ilog(10) as usize + 1;
682+
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
683683
let mut curr = buf.len();
684684

685685
let (n, rem) = udiv_1e19(n);

0 commit comments

Comments
 (0)