Skip to content

Convert ilog(10) to ilog10() #142764

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

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ macro_rules! impl_to_string {
impl SpecToString for $signed {
#[inline]
fn spec_to_string(&self) -> String {
const SIZE: usize = $signed::MAX.ilog(10) as usize + 1;
const SIZE: usize = $signed::MAX.ilog10() as usize + 1;
let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); SIZE];
// Only difference between signed and unsigned are these 8 lines.
let mut out;
Expand All @@ -2861,7 +2861,7 @@ macro_rules! impl_to_string {
impl SpecToString for $unsigned {
#[inline]
fn spec_to_string(&self) -> String {
const SIZE: usize = $unsigned::MAX.ilog(10) as usize + 1;
const SIZE: usize = $unsigned::MAX.ilog10() as usize + 1;
let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); SIZE];

self._fmt(&mut buf).to_string()
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ macro_rules! impl_Display {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(not(feature = "optimize_for_size"))]
{
const MAX_DEC_N: usize = $unsigned::MAX.ilog(10) as usize + 1;
const MAX_DEC_N: usize = $unsigned::MAX.ilog10() as usize + 1;
// Buffer decimals for $unsigned with right alignment.
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];

Expand All @@ -226,7 +226,7 @@ macro_rules! impl_Display {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(not(feature = "optimize_for_size"))]
{
const MAX_DEC_N: usize = $unsigned::MAX.ilog(10) as usize + 1;
const MAX_DEC_N: usize = $unsigned::MAX.ilog10() as usize + 1;
// Buffer decimals for $unsigned with right alignment.
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];

Expand Down Expand Up @@ -323,7 +323,7 @@ macro_rules! impl_Display {

#[cfg(feature = "optimize_for_size")]
fn $gen_name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
const MAX_DEC_N: usize = $u::MAX.ilog(10) as usize + 1;
const MAX_DEC_N: usize = $u::MAX.ilog10() as usize + 1;
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
let mut curr = MAX_DEC_N;
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
Expand Down Expand Up @@ -565,7 +565,7 @@ mod imp {
}
impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128);

const U128_MAX_DEC_N: usize = u128::MAX.ilog(10) as usize + 1;
const U128_MAX_DEC_N: usize = u128::MAX.ilog10() as usize + 1;

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for u128 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub(crate) fn print_src(
);
Ok(())
});
let max_nb_digits = if lines > 0 { lines.ilog(10) + 1 } else { 1 };
let max_nb_digits = if lines > 0 { lines.ilog10() + 1 } else { 1 };
match source_context {
SourceContext::Standalone { file_path } => Source {
code_html: code,
Expand Down
Loading