September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,24 @@
|
|||
extern crate num;
|
||||
use num::traits::One;
|
||||
use std::ops::Mul;
|
||||
|
||||
fn pow<T>(mut base: T, mut exp: usize) -> T
|
||||
where T: Clone + One + Mul<T, Output=T>
|
||||
{
|
||||
if exp == 0 { return T::one() }
|
||||
while exp & 1 == 0 {
|
||||
base = base.clone() * base;
|
||||
exp >>= 1;
|
||||
}
|
||||
if exp == 1 { return base }
|
||||
let mut acc = base.clone();
|
||||
|
||||
while exp > 1 {
|
||||
exp >>= 1;
|
||||
base = base.clone() * base;
|
||||
if exp & 1 == 1 {
|
||||
acc = acc * base.clone();
|
||||
}
|
||||
}
|
||||
acc
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue