2 unstable releases

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

#958 in Math

Download history 139/week @ 2025-03-04 275/week @ 2025-03-11 341/week @ 2025-03-18 110/week @ 2025-03-25 83/week @ 2025-04-01

882 downloads per month

MIT license

2.5MB
239 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]{x**(2n+1)*(-1**n)/(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 mul a_k outer) to check stop iterator
  pub fn sum_arctan_gregory(ax: &[(si_t, si_t)], m: ui_t) -> mpf_s {
    let mut sa = mpf_s::init_set_ui(0);
    let ax = ax.into_iter().map(|&(a, x)|
      (mpf_s::init_set_si(a), mpf_s::init_set_si(x).inv())
    ).collect::<Vec<_>>();
    let _s = (0..=m).try_fold(&mut sa, |mut sa, n| {
      let pre = &mpf_s::init_set(sa);
      let k = 2 * n + 1;
      let mut sn = mpf_s::init_set_ui(0);
      let _a = ax.iter().fold(&mut sn, |mut sn, (a, x)| {
        let s = a * mpf_s::pow_ui(&x, k) / k; // move mul a outer to be faster
        if n & 1 == 1 { sn -= s; } else { sn += s; }
        sn
      });
      sa += sn;
      if sa.cmp(pre) == 0 { None } else { Some(sa) }
    });
    sa
  }

Requirements

License

MIT License

Dependencies

~3–14MB
~140K SLoC