Function ring_algorithm::power

source ·
pub fn power<T, U>(a: T, p: U) -> Twhere
    T: Sized + One + for<'x> MulAssign<&'x T> + for<'x> From<<&'x T as Mul>::Output>,
    for<'x> &'x T: Mul,
    U: Sized + Zero + One + Eq + for<'x> ShrAssign<usize> + for<'x> From<<&'x U as BitAnd>::Output>,
    for<'x> &'x U: BitAnd,
Expand description

calcurate $a^p$ with exponentiation by squaring

use ring_algorithm::power;
assert_eq!(power::<i32, u64>(2, 16), 65536);