-
-
Save skhokhlov/fb5ccf0405a208fb4532 to your computer and use it in GitHub Desktop.
The calculation of the number e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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