| Crates.io | test_gmp_mpir |
| lib.rs | test_gmp_mpir |
| version | 0.4.2 |
| created_at | 2025-03-09 10:19:21.07621+00 |
| updated_at | 2025-04-08 07:56:38.141773+00 |
| description | test gmp mpir for Rust |
| homepage | https://crates.io/crates/test_gmp_mpir |
| repository | https://github.com/nomissbowling/test_gmp_mpir |
| max_upload_size | |
| id | 1585328 |
| size | 2,627,683 |
test gmp mpir for Rust
calc pi/4 sum arctan Gregory
pub fn sum_arctan_gregory(ax: &[(si_t, ui_t)], m: ui_t) -> Self {
let mut sa = mpf_s::from(0);
let ax = ax.into_iter().map(|&(a, x)|
if a < 0 { (1, -a as ui_t, x) } else { (0, a as ui_t, x) } // care range
).collect::<Vec<_>>();
let _s = (0..=m).try_fold(&mut sa, |mut sa, n| {
let pre = &mpf_s::from(&*sa);
let k = 2 * n + 1;
let mut sn = mpf_s::from(0);
let _a = ax.iter().fold(&mut sn, |mut sn, (sgn, a, x)| {
// let s = a * (mpz_s::ui_pow_ui(*x, k) * k).inv_f(); // outer a to faster
let s = a / mpf_s::from(&(mpz_s::ui_pow_ui(*x, k) * k));
if 1 == ((n & 1) ^ sgn) { sn -= s; } else { sn += s; }
sn
});
sa += sn;
if sa.cmp(pre) == 0 { None } else { Some(sa) }
});
sa
}
MIT License