diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 6deb4acb282..e353552cb63 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2476,28 +2476,9 @@ pub const fn checked_ilog(self, base: Self) -> Option { if self <= 0 || base <= 1 { None } else { - let mut n = 0; - let mut r = 1; - - // Optimization for 128 bit wide integers. - if Self::BITS == 128 { - // The following is a correct lower bound for ⌊log(base,self)⌋ because - // - // log(base,self) = log(2,self) / log(2,base) - // ≥ ⌊log(2,self)⌋ / (⌊log(2,base)⌋ + 1) - // - // hence - // - // ⌊log(base,self)⌋ ≥ ⌊ ⌊log(2,self)⌋ / (⌊log(2,base)⌋ + 1) ⌋ . - n = self.ilog2() / (base.ilog2() + 1); - r = base.pow(n); - } - - while r <= self / base { - n += 1; - r *= base; - } - Some(n) + // Delegate to the unsigned implementation. + // The condition makes sure that both casts are exact. + (self as $UnsignedT).checked_ilog(base as $UnsignedT) } }