Skip to content

Instantly share code, notes, and snippets.

@skhokhlov
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save skhokhlov/fb5ccf0405a208fb4532 to your computer and use it in GitHub Desktop.

Select an option

Save skhokhlov/fb5ccf0405a208fb4532 to your computer and use it in GitHub Desktop.
The calculation of the number e
use std::io::File;
fn main(){
let path = Path::new("e.txt");
let display = path.display();
let mut e = 0f64;
let mut k = 1f64;
let mut count = 0f64;
let a = 1.0_f64;
loop {
count = count + a;
e = e + a/k;
k = k * count;
if count == 100.0_f64 {
break;
}
}
println!("e={0}", e);
let mut file = match File::create(&path) {
Err(why) => panic!("couldn't create {}: {}", display, why.desc),
Ok(file) => file,
};
match file.write_be_f64(e) {
Err(why) => {
panic!("couldn't write to {}: {}", display, why.desc)
},
Ok(_) => println!("successfully wrote to {}", display),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment