std-method

Floating-point powi and powf

Raise a value to an integer or floating-point exponent. For fractional powers, check the mathematical domain; precision can vary by platform. Expected stdout (not executed): true true Common mistake: The caret operator is not exponentiation.

Formal Syntax & Structure

rust syntaxrust
x.powi(n: i32); x.powf(n: f64)

Working Example

Example Snippetrust
fn main() {    println!("{}", (2.0_f64.powi(3) - 8.0).abs() < 1e-10);    println!("{}", (16.0_f64.powf(0.5) - 4.0).abs() < 1e-10);}
Rust Reference