test_gmp_mpir

Crates.iotest_gmp_mpir
lib.rstest_gmp_mpir
version0.4.2
created_at2025-03-09 10:19:21.07621+00
updated_at2025-04-08 07:56:38.141773+00
descriptiontest gmp mpir for Rust
homepagehttps://crates.io/crates/test_gmp_mpir
repositoryhttps://github.com/nomissbowling/test_gmp_mpir
max_upload_size
id1585328
size2,627,683
nomissbowling (nomissbowling)

documentation

https://docs.rs/test_gmp_mpir/

README

test_gmp_mpir

test gmp mpir for Rust

Sample

calc pi/4 sum arctan Gregory

  • arctan x = sigma[n=0->inf]{(-1**n)x*(2n+1)/(2n+1)}
  • sum_n = sigma[k=0->ax.len](a_k * arctan_n x_k)
  • result = sigma[n=0->m]sum_n
  • inner loop may be slow (should be outer mul a_k) to check stop iterator
  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
  }

Links

Requirements

License

MIT License

Commit count: 11

cargo fmt