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