Can't get Rust types correct -


use std::num::float;  fn main() {     in 1..101 {         euler(i)     } }  fn euler(x: i32){     let n: i32 = x;     let e: f64 = (1.0+(1.0/n)).powi(n);      println!("euler's number n = {} {}", n, e); } 

i have code , can't compile. i'm pretty new rust appreciated!

let's @ error message:

<anon>:11:28: 11:29 error: mismatched types:  expected `_`,     found `i32` (expected floating-point variable,     found i32) [e0308] <anon>:11     let e: f64 = (1.0+(1.0/n)).powi(n);                                      ^ 

here, rust has very good messages: need provide floating-point variable, not integral one:

let e: f64 = (1.0+(1.0/n f64)).powi(n); // here                ^~~~~~~~ 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -