mpir/
lib.rs

1#![doc(html_root_url = "https://docs.rs/mpir/0.3.1")]
2//! partial Rust porting of mpir multiple precision library based on gmp mpfr
3//!
4//! # Requirements
5//!
6//! - [ gmp ]( https://gmplib.org/ )
7//! - [ mpir ]( https://github.com/ChillMagic/MPIR-Binary )
8//!
9//! in the running directory
10//!
11//! - libgmp-10.dll
12//! - libgmpxx-4.dll (optional)
13//! - mpir.dll
14//!
15//! see also
16//!
17//! - [ https://crates.io/crates/mpir ]( https://crates.io/crates/mpir )
18//! - [ https://github.com/nomissbowling/mpir ]( https://github.com/nomissbowling/mpir )
19//!
20
21pub mod prim;
22pub use crate::prim::{*, typ::*, mpz::*, mpf::*, mpq::*, randstate::*};
23// pub use crate::prim::gmp::*;
24
25pub mod util;
26pub use crate::util::{*};
27
28pub mod minimum;
29
30#[cfg(test)]
31mod tests {
32  use super::*;
33  use super::minimum::{
34    calc_mpz_test,
35    calc_fact_test,
36    calc_fib_test,
37    calc_gcd_test,
38    calc_lcm_test,
39    calc_mod_prime_test,
40    calc_binomial_coefficient_test,
41    calc_mpf_prec64_test, // single thread
42    calc_rand_test, // single thread
43    calc_fit_test, // single thread
44    calc_logical_test,
45    calc_mpq_test,
46    compare_test, // single thread
47    significant_digits_test, // single thread
48    calc_pi_gauss_legendre_test, // single thread
49    calc_pi_euler_test, // single thread
50    calc_napier_test, // single thread
51    ept_test};
52  use serial_test::serial;
53
54  /// with [-- --nocapture] or with [-- --show-output]
55  #[test]
56  fn test_mpz() {
57    let a = &mut mpz_s::new();
58    mpz_init_set_si(a, -123);
59    assert_eq!(format!("{:?}", a),
60      "1, -1 000000000000007b");
61  }
62
63  /// with [-- --nocapture] or with [-- --show-output]
64  #[test]
65  #[serial] // expected on the single thread for mpf_set_default_prec
66  fn test_mpf() {
67    mpf_set_default_prec(64); // 64 bits default
68    let f = &mut mpf_s::new();
69    mpf_init_set_d(f, -0.3);
70    assert_eq!(format!("{:?}", f),
71      "2, -2, 0 0000000000000000 4ccccccccccccc00");
72  }
73
74  /// with [-- --nocapture] or with [-- --show-output]
75  #[test]
76  fn test_mpq() {
77    let q = &mut mpq_s::new();
78    mpq_init(q);
79    mpq_set_ui(q, 2, 8);
80    assert_eq!(format!("{:?}", q),
81      "(1, 1 0000000000000002) / (1, 1 0000000000000008)");
82  }
83
84  /// with [-- --nocapture] or with [-- --show-output]
85  #[test]
86  fn test_calc_mpz() {
87    assert_eq!(calc_mpz_test(), ());
88  }
89
90  /// with [-- --nocapture] or with [-- --show-output]
91  #[test]
92  fn test_calc_fact() {
93    assert_eq!(calc_fact_test(), ());
94  }
95
96  /// with [-- --nocapture] or with [-- --show-output]
97  #[test]
98  fn test_calc_fib() {
99    assert_eq!(calc_fib_test(), ());
100  }
101
102  /// with [-- --nocapture] or with [-- --show-output]
103  #[test]
104  fn test_calc_gcd() {
105    assert_eq!(calc_gcd_test(), ());
106  }
107
108  /// with [-- --nocapture] or with [-- --show-output]
109  #[test]
110  fn test_calc_lcm() {
111    assert_eq!(calc_lcm_test(), ());
112  }
113
114  /// with [-- --nocapture] or with [-- --show-output]
115  #[test]
116  fn test_calc_mod_prime() {
117    assert_eq!(calc_mod_prime_test(), ());
118  }
119
120  /// with [-- --nocapture] or with [-- --show-output]
121  #[test]
122  fn test_calc_binomial_coefficient() {
123    assert_eq!(calc_binomial_coefficient_test(), ());
124  }
125
126  /// with [-- --nocapture] or with [-- --show-output]
127  #[test]
128  #[serial] // expected on the single thread for mpf_set_default_prec
129  fn test_calc_mpf_prec64() {
130    assert_eq!(calc_mpf_prec64_test(), ());
131  }
132
133  /// with [-- --nocapture] or with [-- --show-output]
134  #[test]
135  #[serial] // expected on the single thread for mpf_set_default_prec
136  fn test_calc_rand() {
137    assert_eq!(calc_rand_test(), ());
138  }
139
140  /// with [-- --nocapture] or with [-- --show-output]
141  #[test]
142  #[serial] // expected on the single thread for mpf_set_default_prec
143  fn test_calc_fit() {
144    assert_eq!(calc_fit_test(), ());
145  }
146
147  /// with [-- --nocapture] or with [-- --show-output]
148  #[test]
149  fn test_calc_logical() {
150    assert_eq!(calc_logical_test(), ());
151  }
152
153  /// with [-- --nocapture] or with [-- --show-output]
154  #[test]
155  fn test_calc_mpq() {
156    assert_eq!(calc_mpq_test(), ());
157  }
158
159  /// with [-- --nocapture] or with [-- --show-output]
160  #[test]
161  #[serial] // expected on the single thread for mpf_set_default_prec
162  fn test_compare() {
163    assert_eq!(compare_test(), ());
164  }
165
166  /// with [-- --nocapture] or with [-- --show-output]
167  #[test]
168  #[serial] // expected on the single thread for mpf_set_default_prec
169  fn test_significant_digits() {
170    assert_eq!(significant_digits_test(), ());
171  }
172
173  /// with [-- --nocapture] or with [-- --show-output]
174  #[test]
175  #[serial] // expected on the single thread for mpf_set_default_prec
176  fn test_calc_pi_gauss_legendre() {
177    assert_eq!(calc_pi_gauss_legendre_test(), ());
178  }
179
180  /// with [-- --nocapture] or with [-- --show-output]
181  #[test]
182  #[serial] // expected on the single thread for mpf_set_default_prec
183  fn test_calc_pi_euler() {
184    assert_eq!(calc_pi_euler_test(), ());
185  }
186
187  /// with [-- --nocapture] or with [-- --show-output]
188  #[test]
189  #[serial] // expected on the single thread for mpf_set_default_prec
190  fn test_calc_napier() {
191    assert_eq!(calc_napier_test(), ());
192  }
193
194  /// with [-- --nocapture] or with [-- --show-output]
195  #[test]
196  fn test_ept() {
197    assert_eq!(ept_test(), ());
198  }
199}