File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 0d43e90172c364a5f92a0f4447a5030274f18832
2
+ refs/heads/master: 3219c40e18c20a0dbd41b106e1b05e3696bf4c85
Original file line number Diff line number Diff line change @@ -73,16 +73,19 @@ fn to_str(n: int, radix: uint) -> str {
73
73
fn str ( i : int ) -> str { ret to_str ( i, 10 u) ; }
74
74
75
75
fn pow ( base : int , exponent : uint ) -> int {
76
- ret if exponent == 0 u {
77
- 1
78
- } else if base == 0 {
79
- 0
80
- } else {
81
- let accum = base;
82
- let count = exponent;
83
- while count > 1 u { accum *= base; count -= 1 u; }
84
- accum
85
- } ;
76
+ if exponent == 0 u { ret 1 ; } //Not mathemtically true if [base == 0]
77
+ if base == 0 { ret 0 ; }
78
+ let my_pow = exponent;
79
+ let acc = 1 ;
80
+ let multiplier = base;
81
+ while ( my_pow > 0 u) {
82
+ if my_pow % 2 u == 1 u {
83
+ acc *= multiplier;
84
+ }
85
+ my_pow /= 2 u;
86
+ multiplier *= multiplier;
87
+ }
88
+ ret acc;
86
89
}
87
90
// Local Variables:
88
91
// mode: rust;
You can’t perform that action at this time.
0 commit comments