2

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
RajV
  • 6,860
  • 8
  • 44
  • 62

1 Answers1

8

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

Dogbert
  • 212,659
  • 41
  • 396
  • 397