We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
checked_ilog
base
1 parent 4056082 commit 547b713Copy full SHA for 547b713
1 file changed
library/core/src/num/uint_macros.rs
@@ -1573,7 +1573,14 @@ macro_rules! uint_impl {
1573
if core::intrinsics::is_val_statically_known(base) {
1574
if base == 2 {
1575
return self.checked_ilog2();
1576
- } else if base == 10 {
+ }
1577
+ // change of base:
1578
+ // if base == 2 ** k, then
1579
+ // log(base, n) == log(2, n) / k
1580
+ if base.is_power_of_two() {
1581
+ return Some(try_opt!(self.checked_ilog2()) / base.ilog2());
1582
1583
+ if base == 10 {
1584
return self.checked_ilog10();
1585
}
1586
0 commit comments