feat: add pi

This commit is contained in:
2024-03-24 00:30:31 +08:00
parent e5748b1e41
commit 930c35abff
3 changed files with 22 additions and 0 deletions

7
__std/pi/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "pi"
version = "0.1.0"

8
__std/pi/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "pi"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

7
__std/pi/src/main.rs Normal file
View File

@@ -0,0 +1,7 @@
fn main() {
let mut pi = 1f64;
for i in 1..1000000000u64 {
pi += if i % 2 == 1 { -1f64 } else { 1f64 } / (1f64 + i as f64 * 2f64);
}
println!("pi = {}", pi * 4f64);
}