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.
pow
self
1 parent 8948390 commit 9ab0f63Copy full SHA for 9ab0f63
1 file changed
library/core/src/num/uint_macros.rs
@@ -3315,6 +3315,16 @@ macro_rules! uint_impl {
3315
let mut acc = 1;
3316
3317
if intrinsics::is_val_statically_known(exp) {
3318
+ // change of base:
3319
+ // if base == 2 ** k, then
3320
+ // (2 ** k) ** n
3321
+ // == 2 ** (k * n)
3322
+ // == 1 << (k * n)
3323
+ if self.is_power_of_two() {
3324
+ let k = self.ilog2();
3325
+ return 1 << (k * exp)
3326
+ }
3327
+
3328
while exp > 1 {
3329
if (exp & 1) == 1 {
3330
acc = acc * base;
0 commit comments