在 0.13.0-nightly 中,以下代码将无法编译:
fn main() {
let a = (10.5f64).sqrt();
}
我得到错误:
error: type `f64` does not implement any method in scope named `sqrt`
我做错了什么?
最佳答案
sqrt
方法在 std::num::Float
中trait,所以你需要使用
它:
use std::num::Float;
fn main() {
let a = (10.5f64).sqrt();
println!("{}", a);
}
打印
3.24037
关于rust - 如何在 Rust 0.13.0 中获得平方根?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27531899/