How to get square root in Rust 0.13.0?

2.5k Views Asked by At

In 0.13.0-nightly the following code won't compile:

fn main() {
    let a = (10.5f64).sqrt();
}

I get the error:

error: type `f64` does not implement any method in scope named `sqrt`

What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

sqrt method is in the std::num::Float trait, so you need to use it:

use std::num::Float;

fn main() {
    let a = (10.5f64).sqrt();
    println!("{}", a);
}

prints

3.24037

Demo