Raise a number to a power in Rust

pow

We need to explicitely define the type of the base. We can do it by the type annotation : u128 or using the type suffix _u32.

Then we use the pow function.

examples/raise-to-power/src/main.rs

fn main() {
    let base: u128 = 3;
    let number = base.pow(17);
    println!("{}", number);  // 129140163


    let number = 2_u32.pow(10);
    println!("{}", number);  // 1024
}