2 unstable releases

0.4.2 Apr 8, 2025
0.3.4 Mar 31, 2025
0.2.6 Mar 24, 2025
0.0.3 Mar 13, 2025

#1223 in Math

Download history 189/week @ 2025-03-05 236/week @ 2025-03-12 355/week @ 2025-03-19 133/week @ 2025-03-26 112/week @ 2025-04-02 66/week @ 2025-04-09 15/week @ 2025-04-16

351 downloads per month

MIT license

2.5MB
215 lines

Contains (Windows DLL, 600KB) mpir.dll, (Windows DLL, 600KB) mpir/bin/mpir.dll, (Windows DLL, 510KB) libgmp-10.dll, (Windows DLL, 510KB) mpir/bin/libgmp-10.dll, (static library, 130KB) mpir/lib/libgmp-10.lib, (static library, 125KB) mpir/lib/mpir.lib and 3 more.

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
  }

Requirements

License

MIT License

Dependencies

~3–13MB
~139K SLoC