std-method

Floating-point sqrt and cbrt

Recover a length from a square area or a cube volume. Negative finite inputs have real cube roots but not real square roots. Expected stdout (not executed): 9 -2 true Common mistake: Do not assume a negative argument is valid for every root function.

Formal Syntax & Structure

rust syntaxrust
x.sqrt(); x.cbrt()

Working Example

Example Snippetrust
fn main() {    println!("{}", 81.0_f64.sqrt());    println!("{}", (-8.0_f64).cbrt().round());    println!("{}", (-8.0_f64).sqrt().is_nan());}
Rust Reference