Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Pi/Rust/pi.rust
Normal file
37
Task/Pi/Rust/pi.rust
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use num_bigint::BigInt;
|
||||
|
||||
fn main() {
|
||||
calc_pi();
|
||||
}
|
||||
|
||||
fn calc_pi() {
|
||||
let mut q = BigInt::from(1);
|
||||
let mut r = BigInt::from(0);
|
||||
let mut t = BigInt::from(1);
|
||||
let mut k = BigInt::from(1);
|
||||
let mut n = BigInt::from(3);
|
||||
let mut l = BigInt::from(3);
|
||||
let mut first = true;
|
||||
loop {
|
||||
if &q * 4 + &r - &t < &n * &t {
|
||||
print!("{}", n);
|
||||
if first {
|
||||
print!(".");
|
||||
first = false;
|
||||
}
|
||||
let nr = (&r - &n * &t) * 10;
|
||||
n = (&q * 3 + &r) * 10 / &t - &n * 10;
|
||||
q *= 10;
|
||||
r = nr;
|
||||
} else {
|
||||
let nr = (&q * 2 + &r) * &l;
|
||||
let nn = (&q * &k * 7 + 2 + &r * &l) / (&t * &l);
|
||||
q *= &k;
|
||||
t *= &l;
|
||||
l += 2;
|
||||
k += 1;
|
||||
n = nn;
|
||||
r = nr;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue