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