diff --git a/pi/main.rs b/pi/main.rs index bc694b2..7e7e529 100644 --- a/pi/main.rs +++ b/pi/main.rs @@ -11,11 +11,12 @@ fn main() { let rounds = contents.trim().parse::().unwrap() + 2; + let mut x: f64 = 1.0; let mut pi: f64 = 1.0; - (2..rounds).for_each(|i| { - let x = -1.0f64 + (2.0 * (i & 0x1) as f64); + for i in 2..=rounds { + x = -x; pi += x / (2 * i - 1) as f64; - }); + } println!("{:.16}", pi * 4.0); -} \ No newline at end of file +}