mpir/prim/
mpz.rs

1//! mpz
2//!
3
4use std::fmt;
5use std::error::Error;
6use std::collections::HashMap;
7
8use crate::prim::{*, typ::*, randstate::*, gmp::*}; // mpf::*, mpq::*
9
10/// __mpz_struct
11// not use #[derive(Clone)]
12#[repr(C)]
13pub struct __mpz_struct {
14  /// _mp_alloc
15  pub _mp_alloc: int_t,
16  /// _mp_size
17  pub _mp_size: int_t,
18  /// _mp_d
19  pub _mp_d: *mut mp_limb_t
20}
21
22/// impl SNew
23impl SNew for __mpz_struct {
24  /// new
25  fn new() -> Self {
26    __mpz_struct {
27      _mp_alloc: 0,
28      _mp_size: 0,
29      _mp_d: 0 as *mut mp_limb_t
30    }
31  }
32}
33
34/// impl Drop
35impl Drop for __mpz_struct {
36  fn drop(&mut self) {
37    self.clear()
38  }
39}
40
41/// impl mpz_s
42impl __mpz_struct {
43  /// clear
44  pub fn clear(&mut self) -> () {
45    mpz_clear(self)
46  }
47
48  /// init create new instance
49  pub fn init() -> Self {
50    let mut t = mpz_s::new();
51    mpz_init(&mut t);
52    t
53  }
54
55  /// init2 with prec create new instance
56  pub fn init2(n: mp_bitcnt_t) -> Self {
57    let mut t = mpz_s::new();
58    mpz_init2(&mut t, n);
59    t
60  }
61
62  /// init_set create new instance
63  pub fn init_set(a: mpz_r) -> Self {
64    let mut t = mpz_s::new();
65    mpz_init_set(&mut t, a);
66    t
67  }
68
69  /// init_set_ui create new instance
70  pub fn init_set_ui(u: ui_t) -> Self {
71    let mut t = mpz_s::new();
72    mpz_init_set_ui(&mut t, u);
73    t
74  }
75
76  /// init_set_si create new instance
77  pub fn init_set_si(s: si_t) -> Self {
78    let mut t = mpz_s::new();
79    mpz_init_set_si(&mut t, s);
80    t
81  }
82
83  /// init_set_d create new instance
84  pub fn init_set_d(d: double_t) -> Self {
85    let mut t = mpz_s::new();
86    mpz_init_set_d(&mut t, d);
87    t
88  }
89
90  /// init_set_str create new instance
91  pub fn init_set_str(s: &str, b: int_t) -> Self {
92    let mut t = mpz_s::new();
93    mpz_init_set_str(&mut t, s, b);
94    t
95  }
96
97  /// set self = a
98  pub fn set(&mut self, a: mpz_r) -> &mut Self {
99    mpz_set(self, a);
100    self
101  }
102
103  /// set_ui self = u
104  pub fn set_ui(&mut self, u: ui_t) -> &mut Self {
105    mpz_set_ui(self, u);
106    self
107  }
108
109  /// set_si self = s
110  pub fn set_si(&mut self, s: si_t) -> &mut Self {
111    mpz_set_si(self, s);
112    self
113  }
114
115  /// set_d self = d
116  pub fn set_d(&mut self, d: double_t) -> &mut Self {
117    mpz_set_d(self, d);
118    self
119  }
120
121  /// set_str self from str
122  pub fn set_str(&mut self, s: &str, b: int_t) -> &mut Self {
123    mpz_set_str(self, s, b);
124    self
125  }
126
127  /// fmtstr
128  pub fn fmtstr(&self, b: int_t) -> String {
129    mpz_get_str(None, b, self).expect("mpz fmtstr")
130  }
131
132  /// binstr
133  /// - return "-111111" when bin is "1...11000001"
134  pub fn binstr(&self) -> String {
135    mpz_get_str(None, 2, self).expect("mpz binstr")
136  }
137
138  /// hexstr
139  /// - return "-3f" when hex is "f...c1"
140  pub fn hexstr(&self) -> String {
141    mpz_get_str(None, 16, self).expect("mpz hexstr")
142  }
143
144  /// hexdump
145  /// as String dump of limbs
146  pub fn hexdump(&self) -> String {
147    let d = self.limbs_read();
148    let mut s = vec![format!("{}", self.sgn() as i64 * d.len() as i64)];
149    s.extend(d.iter().rev().map(|u| format!("{:016x}", u))); // to big endian
150    s.join(" ")
151  }
152
153  /// get_d (loss of digits)
154  pub fn get_d(&self) -> double_t {
155    mpz_get_d(self)
156  }
157
158  /// get_ui (loss of digits)
159  pub fn get_ui(&self) -> ui_t {
160    mpz_get_ui(self)
161  }
162
163  /// get_si (loss of digits)
164  pub fn get_si(&self) -> si_t {
165    mpz_get_si(self)
166  }
167
168  /// get_d_2exp (loss of digits)
169  pub fn get_d_2exp(&self) -> (double_t, si_t) {
170    let mut e: si_t = 0;
171    let d = mpz_get_d_2exp(&mut e, self);
172    (d, e)
173  }
174
175  /// swap
176  pub fn swap(&mut self, b: mpz_t) -> &mut Self {
177    mpz_swap(self, b);
178    self
179  }
180
181  /// realloc2
182  pub fn realloc2(&mut self, n: mp_bitcnt_t) -> &mut Self {
183    mpz_realloc2(self, n);
184    self
185  }
186
187  /// _realloc
188  pub fn _realloc(&mut self, sz: mp_size_t) -> &mut Self {
189    _mpz_realloc(self, sz);
190    self
191  }
192
193  /// size
194  pub fn size(&self) -> mp_size_t {
195    mpz_size(self)
196  }
197
198  /// limbs_read slice
199  pub fn limbs_read(&self) -> &[mp_limb_t] {
200    mpz_limbs_read(self)
201  }
202
203  /// getlimbn (single element)
204  pub fn getlimbn(&self, n: mp_size_t) -> mp_limb_t {
205    mpz_getlimbn(self, n)
206  }
207
208  /// limbs_write slice (must call limbs_finish)
209  pub fn limbs_write(&mut self, sz: mp_size_t) -> &mut [mp_limb_t] {
210    mpz_limbs_write(self, sz)
211  }
212
213  /// limbs_modify slice (same as write)
214  pub fn limbs_modify(&mut self, sz: mp_size_t) -> &mut [mp_limb_t] {
215    mpz_limbs_modify(self, sz)
216  }
217
218  /// limbs_finish (used after write or modify to update internal size)
219  pub fn limbs_finish(&mut self, sz: mp_size_t) -> &mut Self {
220    mpz_limbs_finish(self, sz);
221    self
222  }
223
224  /// roinit_n (unsafe) slice single element
225  pub fn roinit_n(&mut self, p: &[mp_limb_t], sz: mp_size_t) -> &mut Self {
226    mpz_roinit_n(self, p, sz)
227  }
228
229  /// cmp
230  pub fn cmp(&self, b: mpz_r) -> int_t {
231    mpz_cmp(self, b)
232  }
233
234  /// cmp_d
235  pub fn cmp_d(&self, d: double_t) -> int_t {
236    mpz_cmp_d(self, d)
237  }
238
239  /// cmp_ui
240  pub fn cmp_ui(&self, u: ui_t) -> int_t {
241    mpz_cmp_ui(self, u)
242  }
243
244  /// cmp_si
245  pub fn cmp_si(&self, s: si_t) -> int_t {
246    mpz_cmp_si(self, s)
247  }
248
249  /// cmpabs
250  pub fn cmpabs(&self, b: mpz_r) -> int_t {
251    mpz_cmpabs(self, b)
252  }
253
254  /// cmpabs_d
255  pub fn cmpabs_d(&self, d: double_t) -> int_t {
256    mpz_cmpabs_d(self, d)
257  }
258
259  /// cmpabs_ui
260  pub fn cmpabs_ui(&self, u: ui_t) -> int_t {
261    mpz_cmpabs_ui(self, u)
262  }
263
264  /// sgn
265  pub fn sgn(&self) -> int_t {
266    mpz_sgn(self)
267  }
268
269  /// root nth root of self create new instance
270  pub fn root(&self, n: ui_t) -> (Self, bool) {
271    let mut t = mpz_s::init();
272    let f = mpz_root(&mut t, self, n);
273    (t, f)
274  }
275
276  /// rootrem (nth root of self, self - root**n) create new instance
277  pub fn rootrem(&self, n: ui_t) -> (Self, Self) {
278    let mut t = mpz_s::init();
279    let mut rem = mpz_s::init();
280    mpz_rootrem(&mut t, &mut rem, self, n);
281    (t, rem)
282  }
283
284  /// sqrt square root of self create new instance
285  pub fn sqrt(&self) -> Self {
286    let mut t = mpz_s::init();
287    mpz_sqrt(&mut t, self);
288    t
289  }
290
291  /// sqrtrem (square root of self, self - root**2) create new instance
292  pub fn sqrtrem(&self) -> (Self, Self) {
293    let mut t = mpz_s::init();
294    let mut rem = mpz_s::init();
295    mpz_sqrtrem(&mut t, &mut rem, self);
296    (t, rem)
297  }
298
299  /// perfect_power_p
300  pub fn perfect_power_p(&self) -> bool {
301    mpz_perfect_power_p(self)
302  }
303
304  /// perfect_square_p
305  pub fn perfect_square_p(&self) -> bool {
306    mpz_perfect_square_p(self)
307  }
308
309  /// primorial_ui c = 2*3*5*7*11*...*p(prev)*p(<=n) create new instance
310  pub fn primorial_ui(n: ui_t) -> Self {
311    let mut t = mpz_s::init_set_ui(1);
312    mpz_primorial_ui(&mut t, n);
313    t
314  }
315
316  /// fac_ui create new instance
317  pub fn fac_ui(n: ui_t) -> Self {
318    let mut t = mpz_s::init_set_ui(1);
319    mpz_fac_ui(&mut t, n);
320    t
321  }
322
323  /// fac2_ui create new instance
324  pub fn fac2_ui(n: ui_t) -> Self {
325    let mut t = mpz_s::init_set_ui(1);
326    mpz_2fac_ui(&mut t, n);
327    t
328  }
329
330  /// mfac_uiui create new instance
331  pub fn mfac_uiui(n: ui_t, m: ui_t) -> Self {
332    let mut t = mpz_s::init_set_ui(1);
333    mpz_mfac_uiui(&mut t, n, m);
334    t
335  }
336
337  /// remove create new instance
338  pub fn remove(&self, f: mpz_r) -> (Self, mp_bitcnt_t) {
339    let mut t = mpz_s::init();
340    let n = mpz_remove(&mut t, self, f);
341    (t, n)
342  }
343
344  /// fib_ui create new instance
345  pub fn fib_ui(n: ui_t) -> Self {
346    let mut f_n = mpz_s::init_set_ui(1);
347    mpz_fib_ui(&mut f_n, n);
348    f_n
349  }
350
351  /// fib2_ui create new instance (f_n, f_nsub1)
352  pub fn fib2_ui(n: ui_t) -> (Self, Self) {
353    let mut f_n = mpz_s::init_set_ui(1);
354    let mut f_nsub1 = mpz_s::init_set_ui(1);
355    mpz_fib2_ui(&mut f_n, &mut f_nsub1, n);
356    (f_n, f_nsub1)
357  }
358
359  /// lucnum_ui create new instance
360  pub fn lucnum_ui(n: ui_t) -> Self {
361    let mut l_n = mpz_s::init_set_ui(1);
362    mpz_lucnum_ui(&mut l_n, n);
363    l_n
364  }
365
366  /// lucnum2_ui create new instance (l_n, l_n_1)
367  pub fn lucnum2_ui(n: ui_t) -> (Self, Self) {
368    let mut l_n = mpz_s::init_set_ui(1);
369    let mut l_n_1 = mpz_s::init_set_ui(1);
370    mpz_lucnum2_ui(&mut l_n, &mut l_n_1, n);
371    (l_n, l_n_1)
372  }
373
374  /// gcd create new instance
375  pub fn gcd(&self, b: mpz_r) -> Self {
376    let mut gcd = mpz_s::init_set_ui(1);
377    mpz_gcd(&mut gcd, self, b);
378    gcd
379  }
380
381  /// gcd_ui create new instance (gcd, gcd: ui_t)
382  /// return 0 when gcd does not fit to ui_t
383  pub fn gcd_ui(&self, u: ui_t) -> (Self, ui_t) {
384    let mut gcd = mpz_s::init_set_ui(1);
385    let u = mpz_gcd_ui(&mut gcd, self, u);
386    (gcd, u)
387  }
388
389  /// gcdext create new instance (gcd, s, t)
390  /// s and t to coefficients satisfying a*s + b*t == gcd
391  pub fn gcdext(&self, b: mpz_r) -> (Self, Self, Self) {
392    let mut gcd = mpz_s::init_set_ui(1);
393    let mut s = mpz_s::init_set_ui(1);
394    let mut t = mpz_s::init_set_ui(1);
395    mpz_gcdext(&mut gcd, &mut s, &mut t, self, b);
396    (gcd, s, t)
397  }
398
399  /// lcm create new instance
400  pub fn lcm(&self, b: mpz_r) -> Self {
401    let mut t = mpz_s::init_set_ui(1);
402    mpz_lcm(&mut t, self, b);
403    t
404  }
405
406  /// lcm_ui create new instance
407  pub fn lcm_ui(&self, u: ui_t) -> Self {
408    let mut t = mpz_s::init_set_ui(1);
409    mpz_lcm_ui(&mut t, self, u);
410    t
411  }
412
413  /// probab_prime_p 2 or 1 or 0
414  pub fn probab_prime_p(&self, r: int_t) -> int_t {
415    mpz_probab_prime_p(self, r)
416  }
417
418  /// nextprime create new instance
419  pub fn nextprime(&self) -> Self {
420    let mut t = mpz_s::init();
421    mpz_nextprime(&mut t, self);
422    t
423  }
424
425/*
426  /// prevprime create new instance
427  pub fn prevprime(&self) -> Self {
428    let mut t = mpz_s::init();
429    mpz_prevprime(&mut t, self);
430    t
431  }
432*/
433
434  /// invert create new instance c = inverse of a mod b ((c*a) mod b == 1)
435  /// returns (undefined, 0) when not exist inverse
436  pub fn invert(a: mpz_r, b: mpz_r) -> (Self, int_t) {
437    let mut t = mpz_s::init();
438    let r = mpz_invert(&mut t, a, b);
439    (t, r)
440  }
441
442  /// jacobi 0 1 -1 (defined only for n odd)
443  pub fn jacobi(&self, n: mpz_r) -> int_t {
444    mpz_jacobi(self, n)
445  }
446
447  /// legendre 0 1 -1 (defined only for p an odd positive prime)
448  pub fn legendre(&self, p: mpz_r) -> int_t {
449    mpz_legendre(self, p)
450  }
451
452  /// kronecker
453  pub fn kronecker(&self, n: mpz_r) -> int_t {
454    mpz_kronecker(self, n)
455  }
456
457  /// kronecker_ui
458  pub fn kronecker_ui(&self, u: ui_t) -> int_t {
459    mpz_kronecker_ui(self, u)
460  }
461
462  /// kronecker_si
463  pub fn kronecker_si(&self, s: si_t) -> int_t {
464    mpz_kronecker_si(self, s)
465  }
466
467  /// ui_kronecker
468  pub fn ui_kronecker(&self, u: ui_t) -> int_t {
469    mpz_ui_kronecker(u, self)
470  }
471
472  /// si_kronecker
473  pub fn si_kronecker(&self, s: si_t) -> int_t {
474    mpz_si_kronecker(s, self)
475  }
476
477  /// bin_ui nCk create new instance
478  pub fn bin_ui(n: mpz_r, k: ui_t) -> Self {
479    let mut t = mpz_s::init();
480    mpz_bin_ui(&mut t, n, k);
481    t
482  }
483
484  /// bin_uiui nCk create new instance
485  pub fn bin_uiui(n: ui_t, k: ui_t) -> Self {
486    let mut t = mpz_s::init();
487    mpz_bin_uiui(&mut t, n, k);
488    t
489  }
490
491  /// abs create new instance
492  pub fn abs(&self) -> Self {
493    let mut t = mpz_s::new();
494    mpz_abs(&mut t, self);
495    t
496  }
497
498  /// neg create new instance
499  pub fn neg(&self) -> Self {
500    let mut t = mpz_s::new();
501    mpz_neg(&mut t, self);
502    t
503  }
504
505  /// sub self -= b
506  pub fn sub(&mut self, b: mpz_r) -> &mut Self {
507    mpz_sub(self, &mpz_s::init_set(self), b);
508    self
509  }
510
511  /// sub_ui self -= u
512  pub fn sub_ui(&mut self, u: ui_t) -> &mut Self {
513    mpz_sub_ui(self, &mpz_s::init_set(self), u);
514    self
515  }
516
517  /// ui_sub self = u - self
518  pub fn ui_sub(&mut self, u: ui_t) -> &mut Self {
519    mpz_ui_sub(self, u, &mpz_s::init_set(self));
520    self
521  }
522
523  /// submul self -= a * b
524  pub fn submul(&mut self, a: mpz_r, b: mpz_r) -> &mut Self {
525    mpz_submul(self, a, b);
526    self
527  }
528
529  /// submul_ui self -= a * u
530  pub fn submul_ui(&mut self, a: mpz_r, u: ui_t) -> &mut Self {
531    mpz_submul_ui(self, a, u);
532    self
533  }
534
535  /// add self += b
536  pub fn add(&mut self, b: mpz_r) -> &mut Self {
537    mpz_add(self, &mpz_s::init_set(self), b);
538    self
539  }
540
541  /// add_ui self += u
542  pub fn add_ui(&mut self, u: ui_t) -> &mut Self {
543    mpz_add_ui(self, &mpz_s::init_set(self), u);
544    self
545  }
546
547  /// addmul self += a * b
548  pub fn addmul(&mut self, a: mpz_r, b: mpz_r) -> &mut Self {
549    mpz_addmul(self, a, b);
550    self
551  }
552
553  /// addmul_ui self += a * u
554  pub fn addmul_ui(&mut self, a: mpz_r, u: ui_t) -> &mut Self {
555    mpz_addmul_ui(self, a, u);
556    self
557  }
558
559  /// mul self *= b
560  pub fn mul(&mut self, b: mpz_r) -> &mut Self {
561    mpz_mul(self, &mpz_s::init_set(self), b);
562    self
563  }
564
565  /// mul_ui self *= u
566  pub fn mul_ui(&mut self, u: ui_t) -> &mut Self {
567    mpz_mul_ui(self, &mpz_s::init_set(self), u);
568    self
569  }
570
571  /// mul_si self *= s
572  pub fn mul_si(&mut self, s: si_t) -> &mut Self {
573    mpz_mul_si(self, &mpz_s::init_set(self), s);
574    self
575  }
576
577  /// mul_2exp self *= 2**n
578  pub fn mul_2exp(&mut self, n: mp_bitcnt_t) -> &mut Self {
579    mpz_mul_2exp(self, &mpz_s::init_set(self), n);
580    self
581  }
582
583  /// cdiv_q create new instance
584  pub fn cdiv_q(&self, d: mpz_r) -> Self {
585    let mut t = mpz_s::init();
586    mpz_cdiv_q(&mut t, self, d);
587    t
588  }
589
590  /// cdiv_r create new instance
591  pub fn cdiv_r(&self, d: mpz_r) -> Self {
592    let mut t = mpz_s::init();
593    mpz_cdiv_r(&mut t, self, d);
594    t
595  }
596
597  /// cdiv_qr create new instance
598  pub fn cdiv_qr(&self, d: mpz_r) -> (Self, Self) {
599    let mut t = mpz_s::init();
600    let mut r = mpz_s::init();
601    mpz_cdiv_qr(&mut t, &mut r, self, d);
602    (t, r)
603  }
604
605  /// cdiv_q_ui create new instance
606  pub fn cdiv_q_ui(&self, d: ui_t) -> (Self, ui_t) {
607    let mut t = mpz_s::init();
608    let u = mpz_cdiv_q_ui(&mut t, self, d);
609    (t, u)
610  }
611
612  /// cdiv_r_ui create new instance
613  pub fn cdiv_r_ui(&self, d: ui_t) -> (Self, ui_t) {
614    let mut t = mpz_s::init();
615    let u = mpz_cdiv_r_ui(&mut t, self, d);
616    (t, u)
617  }
618
619  /// cdiv_qr_ui create new instance
620  pub fn cdiv_qr_ui(&self, d: ui_t) -> (Self, Self, ui_t) {
621    let mut t = mpz_s::init();
622    let mut r = mpz_s::init();
623    let u = mpz_cdiv_qr_ui(&mut t, &mut r, self, d);
624    (t, r, u)
625  }
626
627  /// cdiv_ui
628  pub fn cdiv_ui(&self, d: ui_t) -> ui_t {
629    mpz_cdiv_ui(self, d)
630  }
631
632  /// cdiv_q_2exp create new instance
633  pub fn cdiv_q_2exp(&self, b: mp_bitcnt_t) -> Self {
634    let mut t = mpz_s::init();
635    mpz_cdiv_q_2exp(&mut t, self, b);
636    t
637  }
638
639  /// cdiv_r_2exp create new instance
640  pub fn cdiv_r_2exp(&self, b: mp_bitcnt_t) -> Self {
641    let mut t = mpz_s::init();
642    mpz_cdiv_r_2exp(&mut t, self, b);
643    t
644  }
645
646  /// fdiv_q create new instance
647  pub fn fdiv_q(&self, d: mpz_r) -> Self {
648    let mut t = mpz_s::init();
649    mpz_fdiv_q(&mut t, self, d);
650    t
651  }
652
653  /// fdiv_r create new instance
654  pub fn fdiv_r(&self, d: mpz_r) -> Self {
655    let mut t = mpz_s::init();
656    mpz_fdiv_r(&mut t, self, d);
657    t
658  }
659
660  /// fdiv_qr create new instance
661  pub fn fdiv_qr(&self, d: mpz_r) -> (Self, Self) {
662    let mut t = mpz_s::init();
663    let mut r = mpz_s::init();
664    mpz_fdiv_qr(&mut t, &mut r, self, d);
665    (t, r)
666  }
667
668  /// fdiv_q_ui create new instance
669  pub fn fdiv_q_ui(&self, d: ui_t) -> (Self, ui_t) {
670    let mut t = mpz_s::init();
671    let u = mpz_fdiv_q_ui(&mut t, self, d);
672    (t, u)
673  }
674
675  /// fdiv_r_ui create new instance
676  pub fn fdiv_r_ui(&self, d: ui_t) -> (Self, ui_t) {
677    let mut t = mpz_s::init();
678    let u = mpz_fdiv_r_ui(&mut t, self, d);
679    (t, u)
680  }
681
682  /// fdiv_qr_ui create new instance
683  pub fn fdiv_qr_ui(&self, d: ui_t) -> (Self, Self, ui_t) {
684    let mut t = mpz_s::init();
685    let mut r = mpz_s::init();
686    let u = mpz_fdiv_qr_ui(&mut t, &mut r, self, d);
687    (t, r, u)
688  }
689
690  /// fdiv_ui
691  pub fn fdiv_ui(&self, d: ui_t) -> ui_t {
692    mpz_fdiv_ui(self, d)
693  }
694
695  /// fdiv_q_2exp create new instance
696  pub fn fdiv_q_2exp(&self, b: mp_bitcnt_t) -> Self {
697    let mut t = mpz_s::init();
698    mpz_fdiv_q_2exp(&mut t, self, b);
699    t
700  }
701
702  /// fdiv_r_2exp create new instance
703  pub fn fdiv_r_2exp(&self, b: mp_bitcnt_t) -> Self {
704    let mut t = mpz_s::init();
705    mpz_fdiv_r_2exp(&mut t, self, b);
706    t
707  }
708
709  /// tdiv_q create new instance
710  pub fn tdiv_q(&self, d: mpz_r) -> Self {
711    let mut t = mpz_s::init();
712    mpz_tdiv_q(&mut t, self, d);
713    t
714  }
715
716  /// tdiv_r create new instance
717  pub fn tdiv_r(&self, d: mpz_r) -> Self {
718    let mut t = mpz_s::init();
719    mpz_tdiv_r(&mut t, self, d);
720    t
721  }
722
723  /// tdiv_qr create new instance
724  pub fn tdiv_qr(&self, d: mpz_r) -> (Self, Self) {
725    let mut t = mpz_s::init();
726    let mut r = mpz_s::init();
727    mpz_tdiv_qr(&mut t, &mut r, self, d);
728    (t, r)
729  }
730
731  /// tdiv_q_ui create new instance
732  pub fn tdiv_q_ui(&self, d: ui_t) -> (Self, ui_t) {
733    let mut t = mpz_s::init();
734    let u = mpz_tdiv_q_ui(&mut t, self, d);
735    (t, u)
736  }
737
738  /// tdiv_r_ui create new instance
739  pub fn tdiv_r_ui(&self, d: ui_t) -> (Self, ui_t) {
740    let mut t = mpz_s::init();
741    let u = mpz_tdiv_r_ui(&mut t, self, d);
742    (t, u)
743  }
744
745  /// tdiv_qr_ui create new instance
746  pub fn tdiv_qr_ui(&self, d: ui_t) -> (Self, Self, ui_t) {
747    let mut t = mpz_s::init();
748    let mut r = mpz_s::init();
749    let u = mpz_tdiv_qr_ui(&mut t, &mut r, self, d);
750    (t, r, u)
751  }
752
753  /// tdiv_ui
754  pub fn tdiv_ui(&self, d: ui_t) -> ui_t {
755    mpz_tdiv_ui(self, d)
756  }
757
758  /// tdiv_q_2exp create new instance
759  pub fn tdiv_q_2exp(&self, b: mp_bitcnt_t) -> Self {
760    let mut t = mpz_s::init();
761    mpz_tdiv_q_2exp(&mut t, self, b);
762    t
763  }
764
765  /// tdiv_r_2exp create new instance
766  pub fn tdiv_r_2exp(&self, b: mp_bitcnt_t) -> Self {
767    let mut t = mpz_s::init();
768    mpz_tdiv_r_2exp(&mut t, self, b);
769    t
770  }
771
772  /// modulo create new instance
773  pub fn modulo(&self, d: mpz_r) -> Self {
774    let mut t = mpz_s::init();
775    mpz_mod(&mut t, self, d);
776    t
777  }
778
779  /// mod_ui (the result is always non-negative) create new instance
780  pub fn mod_ui(&self, d: ui_t) -> (Self, ui_t) {
781    let mut t = mpz_s::init();
782    let m = mpz_mod_ui(&mut t, self, d);
783    (t, m)
784  }
785
786  /// divexact create new instance
787  pub fn divexact(&self, d: mpz_r) -> Self {
788    let mut t = mpz_s::init();
789    mpz_divexact(&mut t, self, d);
790    t
791  }
792
793  /// divexact_ui create new instance
794  pub fn divexact_ui(&self, d: ui_t) -> Self {
795    let mut t = mpz_s::init();
796    mpz_divexact_ui(&mut t, self, d);
797    t
798  }
799
800  /// divisible_p
801  pub fn divisible_p(&self, d: mpz_r) -> bool {
802    mpz_divisible_p(self, d)
803  }
804
805  /// divisible_ui_p
806  pub fn divisible_ui_p(&self, d: ui_t) -> bool {
807    mpz_divisible_ui_p(self, d)
808  }
809
810  /// divisible_2exp_p
811  pub fn divisible_2exp_p(&self, b: mp_bitcnt_t) -> bool {
812    mpz_divisible_2exp_p(self, b)
813  }
814
815  /// congruent_p
816  pub fn congruent_p(&self, c: mpz_r, d: mpz_r) -> bool {
817    mpz_congruent_p(self, c, d)
818  }
819
820  /// congruent_ui_p
821  pub fn congruent_ui_p(&self, c: ui_t, d: ui_t) -> bool {
822    mpz_congruent_ui_p(self, c, d)
823  }
824
825  /// congruent_2exp_p
826  pub fn congruent_2exp_p(&self, c: mpz_r, b: mp_bitcnt_t) -> bool {
827    mpz_congruent_2exp_p(self, c, b)
828  }
829
830  /// powm_sec (a**n) mod m ***required n > 0 and m is odd*** create new instance
831  pub fn powm_sec(a: mpz_r, n: mpz_r, m: mpz_r) -> Self {
832    let mut t = mpz_s::new();
833    mpz_powm_sec(&mut t, a, n, m);
834    t
835  }
836
837  /// powm (a**n) mod m ***n < 0 when exists inv a**-1 mod m*** create new instance
838  pub fn powm(a: mpz_r, n: mpz_r, m: mpz_r) -> Self {
839    let mut t = mpz_s::new();
840    mpz_powm(&mut t, a, n, m);
841    t
842  }
843
844  /// powm_ui (a**n) mod m create new instance
845  pub fn powm_ui(a: mpz_r, n: ui_t, m: mpz_r) -> Self {
846    let mut t = mpz_s::new();
847    mpz_powm_ui(&mut t, a, n, m);
848    t
849  }
850
851  /// pow_ui a**n create new instance
852  pub fn pow_ui(a: mpz_r, n: ui_t) -> Self {
853    let mut t = mpz_s::new();
854    mpz_pow_ui(&mut t, a, n);
855    t
856  }
857
858  /// ui_pow_ui a**n create new instance
859  pub fn ui_pow_ui(a: ui_t, n: ui_t) -> Self {
860    let mut t = mpz_s::new();
861    mpz_ui_pow_ui(&mut t, a, n);
862    t
863  }
864
865  /// sizeinbase
866  pub fn sizeinbase(&self, base: int_t) -> mp_size_t {
867    mpz_sizeinbase(self, base)
868  }
869
870  /// even_p
871  pub fn even_p(&self) -> bool {
872    mpz_even_p(self)
873  }
874
875  /// odd_p
876  pub fn odd_p(&self) -> bool {
877    mpz_odd_p(self)
878  }
879
880  /// fits_ulong_p
881  pub fn fits_ulong_p(&self) -> bool {
882    mpz_fits_ulong_p(self)
883  }
884
885  /// fits_slong_p
886  pub fn fits_slong_p(&self) -> bool {
887    mpz_fits_slong_p(self)
888  }
889
890  /// fits_uint_p
891  pub fn fits_uint_p(&self) -> bool {
892    mpz_fits_uint_p(self)
893  }
894
895  /// fits_sint_p
896  pub fn fits_sint_p(&self) -> bool {
897    mpz_fits_sint_p(self)
898  }
899
900  /// fits_ushort_p
901  pub fn fits_ushort_p(&self) -> bool {
902    mpz_fits_ushort_p(self)
903  }
904
905  /// fits_sshort_p
906  pub fn fits_sshort_p(&self) -> bool {
907    mpz_fits_sshort_p(self)
908  }
909
910  /// urandomb create new instance
911  pub fn urandomb(r: randstate_t, nbits: mp_bitcnt_t) -> Self {
912    let mut t = mpz_s::init_set_ui(0);
913    mpz_urandomb(&mut t, r, nbits);
914    t
915  }
916
917  /// urandomm create new instance
918  pub fn urandomm(r: randstate_t, n: mpz_r) -> Self {
919    let mut t = mpz_s::init_set_ui(0);
920    mpz_urandomm(&mut t, r, n);
921    t
922  }
923
924  /// rrandomb create new instance
925  pub fn rrandomb(r: randstate_t, nbits: mp_bitcnt_t) -> Self {
926    let mut t = mpz_s::init_set_ui(0);
927    mpz_rrandomb(&mut t, r, nbits);
928    t
929  }
930
931  /// random create new instance ***(obsoleted) urandomb or urandomm instead***
932  pub fn random(max_size: mp_size_t) -> Self {
933    let mut t = mpz_s::init_set_ui(0);
934    mpz_random(&mut t, max_size);
935    t
936  }
937
938  /// random2 create new instance
939  pub fn random2(max_size: mp_size_t) -> Self {
940    let mut t = mpz_s::init_set_ui(0);
941    mpz_random2(&mut t, max_size);
942    t
943  }
944
945  /// and create new instance
946  pub fn and(&self, b: mpz_r) -> Self {
947    let mut t = mpz_s::init();
948    mpz_and(&mut t, self, b);
949    t
950  }
951
952  /// ior create new instance
953  pub fn ior(&self, b: mpz_r) -> Self {
954    let mut t = mpz_s::init();
955    mpz_ior(&mut t, self, b);
956    t
957  }
958
959  /// xor create new instance
960  pub fn xor(&self, b: mpz_r) -> Self {
961    let mut t = mpz_s::init();
962    mpz_xor(&mut t, self, b);
963    t
964  }
965
966  /// com create new instance
967  pub fn com(&self) -> Self {
968    let mut t = mpz_s::init();
969    mpz_com(&mut t, self);
970    t
971  }
972
973  /// popcount
974  pub fn popcount(&self) -> mp_bitcnt_t {
975    mpz_popcount(self)
976  }
977
978  /// hamdist hamming distance between a and b (both sgn must be same)
979  pub fn hamdist(&self, b: mpz_r) -> mp_bitcnt_t {
980    mpz_hamdist(self, b)
981  }
982
983  /// scan0 to msb
984  pub fn scan0(&self, s: mp_bitcnt_t) -> mp_bitcnt_t {
985    mpz_scan0(self, s)
986  }
987
988  /// scan1 to msb
989  pub fn scan1(&self, s: mp_bitcnt_t) -> mp_bitcnt_t {
990    mpz_scan1(self, s)
991  }
992
993  /// clrbit
994  pub fn clrbit(&mut self, n: mp_bitcnt_t) -> &mut Self {
995    mpz_clrbit(self, n);
996    self
997  }
998
999  /// setbit
1000  pub fn setbit(&mut self, n: mp_bitcnt_t) -> &mut Self {
1001    mpz_setbit(self, n);
1002    self
1003  }
1004
1005  /// combit
1006  pub fn combit(&mut self, n: mp_bitcnt_t) -> &mut Self {
1007    mpz_combit(self, n);
1008    self
1009  }
1010
1011  /// tstbit
1012  pub fn tstbit(&self, n: mp_bitcnt_t) -> bool {
1013    mpz_tstbit(self, n)
1014  }
1015
1016  /// fact create new instance (slow without cache)
1017  pub fn fact(n: ui_t) -> Self {
1018    let mut t = mpz_s::init_set_ui(1);
1019    (1..=n).for_each(|i| { t.mul_ui(i); });
1020    t
1021  }
1022
1023  /// fact cached
1024  pub fn fact_cached(n: ui_t, m: &mut HashMap<ui_t, mpz_s>) -> Self {
1025/*  // duplex mutable borrow m
1026    let e = m.entry(n).or_insert(if n == 0 { mpz_s::init_set_ui(1) }
1027      else { let mut t = mpz_s::fact_cached(n - 1, m); t.mul_ui(n); t }
1028    );
1029    mpz_s::init_set(e) // as clone
1030*/
1031    // early return to avoid duplex mutable borrow m
1032    if let Some(e) = m.get_mut(&n) { return mpz_s::init_set(e); } // as clone
1033    let mut e = if n == 0 { mpz_s::init_set_ui(1) }
1034      else { let mut t = mpz_s::fact_cached(n - 1, m); t.mul_ui(n); t };
1035    m.insert(n, mpz_s::init_set(&mut e)); // as clone
1036    e
1037  }
1038}
1039
1040/// impl Debug
1041impl fmt::Debug for __mpz_struct {
1042  /// fmt
1043  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1044    let mut s = String::from("");
1045unsafe {
1046    std::slice::from_raw_parts(self._mp_d, self._mp_alloc as usize).iter()
1047      .for_each(|d| s += format!(" {:016x}", d).as_str())
1048}
1049    write!(f, "{}, {}{}", self._mp_alloc, self._mp_size, s)
1050  }
1051}
1052
1053/// impl Display
1054impl fmt::Display for __mpz_struct {
1055  /// fmt
1056  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1057    write!(f, "{}", self.fmtstr(10))
1058  }
1059}
1060
1061/// mpz_s
1062#[allow(non_camel_case_types)]
1063pub type mpz_s = __mpz_struct; // [__mpz_struct; 1]
1064/// mpz_t
1065#[allow(non_camel_case_types)]
1066pub type mpz_t<'a> = &'a mut mpz_s; // *mut mpz_s
1067/// mpz_r
1068#[allow(non_camel_case_types)]
1069pub type mpz_r<'a> = &'a mpz_s; // *const mpz_s
1070
1071/// mpz_clears
1072pub fn mpz_clears(va: &mut Vec<mpz_t>) -> () {
1073  va.iter_mut().for_each(|a| {
1074    unsafe { __gmpz_clear(*a) } // not use __gmpz_clears
1075  })
1076}
1077
1078/// mpz_clear
1079pub fn mpz_clear(a: mpz_t) -> () {
1080  unsafe { __gmpz_clear(a) }
1081}
1082
1083/// mpz_inits
1084pub fn mpz_inits(va: &mut Vec<mpz_t>) -> () {
1085  va.iter_mut().for_each(|a| {
1086    unsafe { __gmpz_init(*a) } // not use __gmpz_inits
1087  })
1088}
1089
1090/// mpz_init
1091pub fn mpz_init(a: mpz_t) -> () {
1092  unsafe { __gmpz_init(a) }
1093}
1094
1095/// mpz_init2
1096pub fn mpz_init2(a: mpz_t, n: mp_bitcnt_t) -> () {
1097  unsafe { __gmpz_init2(a, n) }
1098}
1099
1100/// mpz_init_set
1101pub fn mpz_init_set(a: mpz_t, b: mpz_r) -> () {
1102  unsafe { __gmpz_init_set(a, b) }
1103}
1104
1105/// mpz_init_set_ui
1106pub fn mpz_init_set_ui(a: mpz_t, u: ui_t) -> () {
1107  unsafe { __gmpz_init_set_ui(a, u) }
1108}
1109
1110/// mpz_init_set_si
1111pub fn mpz_init_set_si(a: mpz_t, s: si_t) -> () {
1112  unsafe { __gmpz_init_set_si(a, s) }
1113}
1114
1115/// mpz_init_set_d
1116pub fn mpz_init_set_d(a: mpz_t, d: double_t) -> () {
1117  unsafe { __gmpz_init_set_d(a, d) }
1118}
1119
1120/// mpz_init_set_str
1121pub fn mpz_init_set_str(a: mpz_t, s: &str, b: int_t) -> () {
1122  mpz_init_set_str_u8z(a, to_u8z!(s), b)
1123}
1124
1125/// mpz_init_set_str_u8z
1126pub fn mpz_init_set_str_u8z(a: mpz_t, s: &[u8], b: int_t) -> () {
1127  unsafe { __gmpz_init_set_str(a, s as *const [u8] as *const u8, b) }
1128}
1129
1130/// mpz_set
1131pub fn mpz_set(a: mpz_t, b: mpz_r) -> () {
1132  unsafe { __gmpz_set(a, b) }
1133}
1134
1135/// mpz_set_ui
1136pub fn mpz_set_ui(a: mpz_t, u: ui_t) -> () {
1137  unsafe { __gmpz_set_ui(a, u) }
1138}
1139
1140/// mpz_set_si
1141pub fn mpz_set_si(a: mpz_t, s: si_t) -> () {
1142  unsafe { __gmpz_set_si(a, s) }
1143}
1144
1145/// mpz_set_d
1146pub fn mpz_set_d(a: mpz_t, d: double_t) -> () {
1147  unsafe { __gmpz_set_d(a, d) }
1148}
1149
1150/// mpz_set_str
1151pub fn mpz_set_str(a: mpz_t, s: &str, b: int_t) -> () {
1152  mpz_set_str_u8z(a, to_u8z!(s), b)
1153}
1154
1155/// mpz_set_str_u8z
1156pub fn mpz_set_str_u8z(a: mpz_t, s: &[u8], b: int_t) -> () {
1157  unsafe { __gmpz_set_str(a, s as *const [u8] as *const u8, b) }
1158}
1159
1160/// mpz_get_u8z
1161pub fn mpz_get_u8z<'a>(s: Option<&mut [u8]>, b: int_t, a: &'a mpz_s) ->
1162  Option<Vec<u8>> {
1163  let ff = s == None;
1164unsafe {
1165  let p = __gmpz_get_str(
1166    match s { None => 0 as *mut u8, Some(s) => s as *mut [u8] as *mut u8 },
1167    b, a);
1168  u8zvec(p, ff)
1169}
1170}
1171
1172/// mpz_get_str
1173/// the length of mut String must larger than mpz_t display length
1174pub fn mpz_get_str<'a>(s: Option<&mut String>, b: int_t, a: &'a mpz_s) ->
1175  Result<String, Box<dyn Error>> {
1176  let r = mpz_get_u8z(
1177    match s { None => None, Some(s) => Some(unsafe { s.as_bytes_mut() }) },
1178    b, a);
1179  match r {
1180  None => Err("err mpz get str".into()),
1181  Some(r) => Ok(String::from_utf8(r)?)
1182  }
1183}
1184
1185/// mpz_get_d
1186pub fn mpz_get_d(a: mpz_r) -> double_t {
1187  unsafe { __gmpz_get_d(a) }
1188}
1189
1190/// mpz_get_ui
1191pub fn mpz_get_ui(a: mpz_r) -> ui_t {
1192  unsafe { __gmpz_get_ui(a) }
1193}
1194
1195/// mpz_get_si
1196pub fn mpz_get_si(a: mpz_r) -> si_t {
1197  unsafe { __gmpz_get_si(a) }
1198}
1199
1200/// mpz_get_d_2exp
1201pub fn mpz_get_d_2exp(e: &mut si_t, a: mpz_r) -> double_t {
1202  unsafe { __gmpz_get_d_2exp(e, a) }
1203}
1204
1205/// mpz_swap
1206pub fn mpz_swap(a: mpz_t, b: mpz_t) -> () {
1207  unsafe { __gmpz_swap(a, b) }
1208}
1209
1210/// mpz_realloc2
1211pub fn mpz_realloc2(a: mpz_t, n: mp_bitcnt_t) -> () {
1212  unsafe { __gmpz_realloc2(a, n) }
1213}
1214
1215/// _mpz_realloc
1216pub fn _mpz_realloc(a: mpz_t, sz: mp_size_t) -> mp_t {
1217  unsafe { __gmpz_realloc(a, sz) }
1218}
1219
1220/// mpz_array_init ***(obsoleted) do NOT use it***
1221pub fn mpz_array_init(a: mpz_t, sz: mp_size_t, fnb: mp_size_t) -> () {
1222  unsafe { __gmpz_array_init(a, sz, fnb) }
1223}
1224
1225/// mpz_size
1226pub fn mpz_size(a: mpz_r) -> mp_size_t {
1227  unsafe { __gmpz_size(a) }
1228}
1229
1230/// mpz_limbs_read slice
1231pub fn mpz_limbs_read(a: mpz_r) -> &[mp_limb_t] {
1232  let sz = mpz_size(a);
1233  unsafe { std::slice::from_raw_parts(__gmpz_limbs_read(a), sz) }
1234}
1235
1236/// mpz_getlimbn (single element)
1237pub fn mpz_getlimbn(a: mpz_r, n: mp_size_t) -> mp_limb_t {
1238  unsafe { __gmpz_getlimbn(a, n) }
1239}
1240
1241/// mpz_limbs_write slice
1242pub fn mpz_limbs_write(a: mpz_t, sz: mp_size_t) -> &mut [mp_limb_t] {
1243  unsafe { std::slice::from_raw_parts_mut(__gmpz_limbs_write(a, sz), sz) }
1244}
1245
1246/// mpz_limbs_modify slice
1247pub fn mpz_limbs_modify(a: mpz_t, sz: mp_size_t) -> &mut [mp_limb_t] {
1248  unsafe { std::slice::from_raw_parts_mut(__gmpz_limbs_modify(a, sz), sz) }
1249}
1250
1251/// mpz_limbs_finish (used after write or modify to update internal size)
1252pub fn mpz_limbs_finish(a: mpz_t, sz: mp_size_t) -> () {
1253  unsafe { __gmpz_limbs_finish(a, sz) }
1254}
1255
1256/// mpz_roinit_n (unsafe) slice single element
1257pub fn mpz_roinit_n<'a>(a: mpz_t,
1258  p: &[mp_limb_t], sz: mp_size_t) -> mpz_t<'a> {
1259  unsafe {
1260    let q = __gmpz_roinit_n(a,
1261      p as *const [mp_limb_t] as *const mp_limb_t, sz);
1262    &mut std::slice::from_raw_parts_mut(q, 1)[0]
1263  }
1264}
1265
1266/// MPZ_ROINIT_N (unsafe) create new instance of mpz_s ***NOT same as gmp***
1267#[allow(non_snake_case)]
1268pub fn MPZ_ROINIT_N(p: &mut [mp_limb_t], sz: mp_size_t) -> mpz_s {
1269  __mpz_struct {
1270    _mp_alloc: 0,
1271    _mp_size: sz as int_t,
1272    _mp_d: p as *mut [mp_limb_t] as *mut mp_limb_t
1273  }
1274}
1275
1276/// mpz_cmp
1277pub fn mpz_cmp(a: mpz_r, b: mpz_r) -> int_t {
1278  unsafe { __gmpz_cmp(a, b) }
1279}
1280
1281/// mpz_cmp_d
1282pub fn mpz_cmp_d(a: mpz_r, d: double_t) -> int_t {
1283  unsafe { __gmpz_cmp_d(a, d) }
1284}
1285
1286/// mpz_cmp_ui
1287pub fn mpz_cmp_ui(a: mpz_r, u: ui_t) -> int_t {
1288  unsafe { __gmpz_cmp_ui(a, u) }
1289}
1290
1291/// mpz_cmp_si
1292pub fn mpz_cmp_si(a: mpz_r, s: si_t) -> int_t {
1293  unsafe { __gmpz_cmp_si(a, s) }
1294}
1295
1296/// mpz_cmpabs
1297pub fn mpz_cmpabs(a: mpz_r, b: mpz_r) -> int_t {
1298  unsafe { __gmpz_cmpabs(a, b) }
1299}
1300
1301/// mpz_cmpabs_d
1302pub fn mpz_cmpabs_d(a: mpz_r, d: double_t) -> int_t {
1303  unsafe { __gmpz_cmpabs_d(a, d) }
1304}
1305
1306/// mpz_cmpabs_ui
1307pub fn mpz_cmpabs_ui(a: mpz_r, u: ui_t) -> int_t {
1308  unsafe { __gmpz_cmpabs_ui(a, u) }
1309}
1310
1311/// mpz_sgn
1312pub fn mpz_sgn(a: mpz_r) -> int_t {
1313//  unsafe { __gmpz_sgn(a) }
1314  let t = a._mp_size;
1315  if t < 0 { -1 } else { if t > 0 { 1 } else { 0 } }
1316}
1317
1318/// mpz_root r = nth root of a
1319pub fn mpz_root(r: mpz_t, a: mpz_r, n: ui_t) -> bool {
1320  unsafe { __gmpz_root(r, a, n) != 0 }
1321}
1322
1323/// mpz_rootrem r = nth root of u, rem = u - r**n (to the remainder)
1324pub fn mpz_rootrem(r: mpz_t, rem: mpz_t, u: mpz_r, n: ui_t) -> () {
1325  unsafe { __gmpz_rootrem(r, rem, u, n) }
1326}
1327
1328/// mpz_sqrt r = square root of a
1329pub fn mpz_sqrt(r: mpz_t, a: mpz_r) -> () {
1330  unsafe { __gmpz_sqrt(r, a) }
1331}
1332
1333/// mpz_sqrtrem r = square root of u, rem = u - r**2 (to the remainder)
1334pub fn mpz_sqrtrem(r: mpz_t, rem: mpz_t, u: mpz_r) -> () {
1335  unsafe { __gmpz_sqrtrem(r, rem, u) }
1336}
1337
1338/// mpz_perfect_power_p
1339pub fn mpz_perfect_power_p(a: mpz_r) -> bool {
1340  unsafe { __gmpz_perfect_power_p(a) != 0 }
1341}
1342
1343/// mpz_perfect_square_p
1344pub fn mpz_perfect_square_p(a: mpz_r) -> bool {
1345  unsafe { __gmpz_perfect_square_p(a) != 0 }
1346}
1347
1348/// mpz_primorial_ui c = 2*3*5*7*11*...*p(prev)*p(&lt;=n)
1349pub fn mpz_primorial_ui(c: mpz_t, n: ui_t) -> () {
1350  unsafe { __gmpz_primorial_ui(c, n) }
1351}
1352
1353/// mpz_fac_ui c = n!
1354pub fn mpz_fac_ui(c: mpz_t, n: ui_t) -> () {
1355  unsafe { __gmpz_fac_ui(c, n) }
1356}
1357
1358/// mpz_2fac_ui c = n!!
1359pub fn mpz_2fac_ui(c: mpz_t, n: ui_t) -> () {
1360  unsafe { __gmpz_2fac_ui(c, n) }
1361}
1362
1363/// mpz_mfac_uiui c = n! ** m
1364pub fn mpz_mfac_uiui(c: mpz_t, n: ui_t, m: ui_t) -> () {
1365  unsafe { __gmpz_mfac_uiui(c, n, m) }
1366}
1367
1368/// mpz_remove
1369pub fn mpz_remove(c: mpz_t, a: mpz_r, f: mpz_r) -> mp_bitcnt_t {
1370  unsafe { __gmpz_remove(c, a, f) }
1371}
1372
1373/// mpz_fib_ui
1374pub fn mpz_fib_ui(f_n: mpz_t, n: ui_t) -> () {
1375  unsafe { __gmpz_fib_ui(f_n, n) }
1376}
1377
1378/// mpz_fib2_ui
1379pub fn mpz_fib2_ui(f_n: mpz_t, f_nsub1: mpz_t, n: ui_t) -> () {
1380  unsafe { __gmpz_fib2_ui(f_n, f_nsub1, n) }
1381}
1382
1383/// mpz_lucnum_ui
1384pub fn mpz_lucnum_ui(l_n: mpz_t, n: ui_t) -> () {
1385  unsafe { __gmpz_lucnum_ui(l_n, n) }
1386}
1387
1388/// mpz_lucnum2_ui
1389pub fn mpz_lucnum2_ui(l_n: mpz_t, l_n_1: mpz_t, n: ui_t) -> () {
1390  unsafe { __gmpz_lucnum2_ui(l_n, l_n_1, n) }
1391}
1392
1393/// mpz_gcd
1394pub fn mpz_gcd(g: mpz_t, a: mpz_r, b: mpz_r) -> () {
1395  unsafe { __gmpz_gcd(g, a, b) }
1396}
1397
1398/// mpz_gcd_ui return 0 when gcd does not fit to ui_t
1399pub fn mpz_gcd_ui(g: mpz_t, a: mpz_r, u: ui_t) -> ui_t {
1400  unsafe { __gmpz_gcd_ui(g, a, u) }
1401}
1402
1403/// mpz_gcdext s and t to coefficients satisfying a*s + b*t == gcd
1404pub fn mpz_gcdext(g: mpz_t, s: mpz_t, t: mpz_t, a: mpz_r, b: mpz_r) -> () {
1405  unsafe { __gmpz_gcdext(g, s, t, a, b) }
1406}
1407
1408/// mpz_lcm
1409pub fn mpz_lcm(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1410  unsafe { __gmpz_lcm(c, a, b) }
1411}
1412
1413/// mpz_lcm_ui
1414pub fn mpz_lcm_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1415  unsafe { __gmpz_lcm_ui(c, a, u) }
1416}
1417
1418/// mpz_probab_prime_p 2 or 1 or 0
1419pub fn mpz_probab_prime_p(a: mpz_r, r: int_t) -> int_t {
1420  unsafe { __gmpz_probab_prime_p(a, r) }
1421}
1422
1423/// mpz_nextprime
1424pub fn mpz_nextprime(c: mpz_t, a: mpz_r) -> () {
1425  unsafe { __gmpz_nextprime(c, a) }
1426}
1427
1428/*
1429/// mpz_prevprime
1430pub fn mpz_prevprime(c: mpz_t, a: mpz_r) -> () {
1431  unsafe { __gmpz_prevprime(c, a) }
1432}
1433*/
1434
1435/// mpz_invert c = inverse of a mod b ((c*a) mod b == 1)
1436pub fn mpz_invert(c: mpz_t, a: mpz_r, b: mpz_r) -> int_t {
1437  unsafe { __gmpz_invert(c, a, b) }
1438}
1439
1440/// mpz_jacobi 0 1 -1 (defined only for n odd)
1441pub fn mpz_jacobi(a: mpz_r, n: mpz_r) -> int_t {
1442  unsafe { __gmpz_jacobi(a, n) }
1443}
1444
1445/// mpz_legendre 0 1 -1 (defined only for p an odd positive prime)
1446pub fn mpz_legendre(a: mpz_r, p: mpz_r) -> int_t {
1447  unsafe { __gmpz_legendre(a, p) }
1448}
1449
1450/// mpz_kronecker
1451pub fn mpz_kronecker(a: mpz_r, n: mpz_r) -> int_t {
1452/*
1453  unsafe { __gmpz_kronecker(a, n) }
1454*/
1455  unsafe { __gmpz_jacobi(a, n) }
1456}
1457
1458/// mpz_kronecker_ui
1459pub fn mpz_kronecker_ui(a: mpz_r, u: ui_t) -> int_t {
1460  unsafe { __gmpz_kronecker_ui(a, u) }
1461}
1462
1463/// mpz_kronecker_si
1464pub fn mpz_kronecker_si(a: mpz_r, s: si_t) -> int_t {
1465  unsafe { __gmpz_kronecker_si(a, s) }
1466}
1467
1468/// mpz_ui_kronecker
1469pub fn mpz_ui_kronecker(u: ui_t, a: mpz_r) -> int_t {
1470  unsafe { __gmpz_ui_kronecker(u, a) }
1471}
1472
1473/// mpz_si_kronecker
1474pub fn mpz_si_kronecker(s: si_t, a: mpz_r) -> int_t {
1475  unsafe { __gmpz_si_kronecker(s, a) }
1476}
1477
1478/// mpz_bin_ui nCk
1479pub fn mpz_bin_ui(c: mpz_t, n: mpz_r, k: ui_t) -> () {
1480  unsafe { __gmpz_bin_ui(c, n, k) }
1481}
1482
1483/// mpz_bin_uiui nCk
1484pub fn mpz_bin_uiui(c: mpz_t, n: ui_t, k: ui_t) -> () {
1485  unsafe { __gmpz_bin_uiui(c, n, k) }
1486}
1487
1488/// mpz_abs
1489pub fn mpz_abs(c: mpz_t, a: mpz_r) -> () {
1490  unsafe { __gmpz_abs(c, a) }
1491}
1492
1493/// mpz_neg
1494pub fn mpz_neg(c: mpz_t, a: mpz_r) -> () {
1495  unsafe { __gmpz_neg(c, a) }
1496}
1497
1498/// mpz_sub c = a - b
1499pub fn mpz_sub(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1500  unsafe { __gmpz_sub(c, a, b) }
1501}
1502
1503/// mpz_sub_ui c = a - u
1504pub fn mpz_sub_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1505  unsafe { __gmpz_sub_ui(c, a, u) }
1506}
1507
1508/// mpz_ui_sub c = u - a
1509pub fn mpz_ui_sub(c: mpz_t, u: ui_t, a: mpz_r) -> () {
1510  unsafe { __gmpz_ui_sub(c, u, a) }
1511}
1512
1513/// mpz_submul c -= a * b
1514pub fn mpz_submul(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1515  unsafe { __gmpz_submul(c, a, b) }
1516}
1517
1518/// mpz_submul_ui c -= a * u
1519pub fn mpz_submul_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1520  unsafe { __gmpz_submul_ui(c, a, u) }
1521}
1522
1523/// mpz_add c = a + b
1524pub fn mpz_add(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1525  unsafe { __gmpz_add(c, a, b) }
1526}
1527
1528/// mpz_add_ui c = a + u
1529pub fn mpz_add_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1530  unsafe { __gmpz_add_ui(c, a, u) }
1531}
1532
1533/// mpz_addmul c += a * b
1534pub fn mpz_addmul(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1535  unsafe { __gmpz_addmul(c, a, b) }
1536}
1537
1538/// mpz_addmul_ui c += a * u
1539pub fn mpz_addmul_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1540  unsafe { __gmpz_addmul_ui(c, a, u) }
1541}
1542
1543/// mpz_mul c = a * b
1544pub fn mpz_mul(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1545  unsafe { __gmpz_mul(c, a, b) }
1546}
1547
1548/// mpz_mul_ui c = a * u
1549pub fn mpz_mul_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1550  unsafe { __gmpz_mul_ui(c, a, u) }
1551}
1552
1553/// mpz_mul_si c = a * s
1554pub fn mpz_mul_si(c: mpz_t, a: mpz_r, s: si_t) -> () {
1555  unsafe { __gmpz_mul_si(c, a, s) }
1556}
1557
1558/// mpz_mul_2exp c = a * 2**n
1559pub fn mpz_mul_2exp(c: mpz_t, a: mpz_r, n: mp_bitcnt_t) -> () {
1560  unsafe { __gmpz_mul_2exp(c, a, n) }
1561}
1562
1563/// mpz_cdiv_q
1564pub fn mpz_cdiv_q(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1565  unsafe { __gmpz_cdiv_q(q, n, d) }
1566}
1567
1568/// mpz_cdiv_r
1569pub fn mpz_cdiv_r(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1570  unsafe { __gmpz_cdiv_r(r, n, d) }
1571}
1572
1573/// mpz_cdiv_qr
1574pub fn mpz_cdiv_qr(q: mpz_t, r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1575  unsafe { __gmpz_cdiv_qr(q, r, n, d) }
1576}
1577
1578/// mpz_cdiv_q_ui
1579pub fn mpz_cdiv_q_ui(q: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1580  unsafe { __gmpz_cdiv_q_ui(q, n, d) }
1581}
1582
1583/// mpz_cdiv_r_ui
1584pub fn mpz_cdiv_r_ui(r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1585  unsafe { __gmpz_cdiv_r_ui(r, n, d) }
1586}
1587
1588/// mpz_cdiv_qr_ui
1589pub fn mpz_cdiv_qr_ui(q: mpz_t, r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1590  unsafe { __gmpz_cdiv_qr_ui(q, r, n, d) }
1591}
1592
1593/// mpz_cdiv_ui
1594pub fn mpz_cdiv_ui(n: mpz_r, d: ui_t) -> ui_t {
1595  unsafe { __gmpz_cdiv_ui(n, d) }
1596}
1597
1598/// mpz_cdiv_q_2exp
1599pub fn mpz_cdiv_q_2exp(q: mpz_t, n: mpz_r, b: mp_bitcnt_t) -> () {
1600  unsafe { __gmpz_cdiv_q_2exp(q, n, b) }
1601}
1602
1603/// mpz_cdiv_r_2exp
1604pub fn mpz_cdiv_r_2exp(r: mpz_t, n: mpz_r, b: mp_bitcnt_t) -> () {
1605  unsafe { __gmpz_cdiv_r_2exp(r, n, b) }
1606}
1607
1608/// mpz_fdiv_q
1609pub fn mpz_fdiv_q(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1610  unsafe { __gmpz_fdiv_q(q, n, d) }
1611}
1612
1613/// mpz_fdiv_r
1614pub fn mpz_fdiv_r(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1615  unsafe { __gmpz_fdiv_r(r, n, d) }
1616}
1617
1618/// mpz_fdiv_qr
1619pub fn mpz_fdiv_qr(q: mpz_t, r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1620  unsafe { __gmpz_fdiv_qr(q, r, n, d) }
1621}
1622
1623/// mpz_fdiv_q_ui
1624pub fn mpz_fdiv_q_ui(q: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1625  unsafe { __gmpz_fdiv_q_ui(q, n, d) }
1626}
1627
1628/// mpz_fdiv_r_ui
1629pub fn mpz_fdiv_r_ui(r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1630  unsafe { __gmpz_fdiv_r_ui(r, n, d) }
1631}
1632
1633/// mpz_fdiv_qr_ui
1634pub fn mpz_fdiv_qr_ui(q: mpz_t, r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1635  unsafe { __gmpz_fdiv_qr_ui(q, r, n, d) }
1636}
1637
1638/// mpz_fdiv_ui
1639pub fn mpz_fdiv_ui(n: mpz_r, d: ui_t) -> ui_t {
1640  unsafe { __gmpz_fdiv_ui(n, d) }
1641}
1642
1643/// mpz_fdiv_q_2exp
1644pub fn mpz_fdiv_q_2exp(q: mpz_t, n: mpz_r, b: mp_bitcnt_t) -> () {
1645  unsafe { __gmpz_fdiv_q_2exp(q, n, b) }
1646}
1647
1648/// mpz_fdiv_r_2exp
1649pub fn mpz_fdiv_r_2exp(r: mpz_t, n: mpz_r, b: mp_bitcnt_t) -> () {
1650  unsafe { __gmpz_fdiv_r_2exp(r, n, b) }
1651}
1652
1653/// mpz_tdiv_q
1654pub fn mpz_tdiv_q(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1655  unsafe { __gmpz_tdiv_q(q, n, d) }
1656}
1657
1658/// mpz_tdiv_r
1659pub fn mpz_tdiv_r(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1660  unsafe { __gmpz_tdiv_r(r, n, d) }
1661}
1662
1663/// mpz_tdiv_qr
1664pub fn mpz_tdiv_qr(q: mpz_t, r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1665  unsafe { __gmpz_tdiv_qr(q, r, n, d) }
1666}
1667
1668/// mpz_tdiv_q_ui
1669pub fn mpz_tdiv_q_ui(q: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1670  unsafe { __gmpz_tdiv_q_ui(q, n, d) }
1671}
1672
1673/// mpz_tdiv_r_ui
1674pub fn mpz_tdiv_r_ui(r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1675  unsafe { __gmpz_tdiv_r_ui(r, n, d) }
1676}
1677
1678/// mpz_tdiv_qr_ui
1679pub fn mpz_tdiv_qr_ui(q: mpz_t, r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1680  unsafe { __gmpz_tdiv_qr_ui(q, r, n, d) }
1681}
1682
1683/// mpz_tdiv_ui
1684pub fn mpz_tdiv_ui(n: mpz_r, d: ui_t) -> ui_t {
1685  unsafe { __gmpz_tdiv_ui(n, d) }
1686}
1687
1688/// mpz_tdiv_q_2exp
1689pub fn mpz_tdiv_q_2exp(q: mpz_t, n: mpz_r, b: mp_bitcnt_t) -> () {
1690  unsafe { __gmpz_tdiv_q_2exp(q, n, b) }
1691}
1692
1693/// mpz_tdiv_r_2exp
1694pub fn mpz_tdiv_r_2exp(r: mpz_t, n: mpz_r, b: mp_bitcnt_t) -> () {
1695  unsafe { __gmpz_tdiv_r_2exp(r, n, b) }
1696}
1697
1698/// mpz_mod
1699pub fn mpz_mod(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1700  unsafe { __gmpz_mod(r, n, d) }
1701}
1702
1703/// mpz_mod_ui
1704pub fn mpz_mod_ui(r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1705//  unsafe { __gmpz_mod_ui(r, n, d) }
1706  unsafe { __gmpz_fdiv_r_ui(r, n, d) }
1707}
1708
1709/// mpz_divexact
1710pub fn mpz_divexact(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1711  unsafe { __gmpz_divexact(q, n, d) }
1712}
1713
1714/// mpz_divexact_ui
1715pub fn mpz_divexact_ui(q: mpz_t, n: mpz_r, d: ui_t) -> () {
1716  unsafe { __gmpz_divexact_ui(q, n, d) }
1717}
1718
1719/// mpz_divisible_p
1720pub fn mpz_divisible_p(n: mpz_r, d: mpz_r) -> bool {
1721  unsafe { __gmpz_divisible_p(n, d) != 0 }
1722}
1723
1724/// mpz_divisible_ui_p
1725pub fn mpz_divisible_ui_p(n: mpz_r, d: ui_t) -> bool {
1726  unsafe { __gmpz_divisible_ui_p(n, d) != 0 }
1727}
1728
1729/// mpz_divisible_2exp_p
1730pub fn mpz_divisible_2exp_p(n: mpz_r, b: mp_bitcnt_t) -> bool {
1731  unsafe { __gmpz_divisible_2exp_p(n, b) != 0 }
1732}
1733
1734/// mpz_congruent_p
1735pub fn mpz_congruent_p(n: mpz_r, c: mpz_r, d: mpz_r) -> bool {
1736  unsafe { __gmpz_congruent_p(n, c, d) != 0 }
1737}
1738
1739/// mpz_congruent_ui_p
1740pub fn mpz_congruent_ui_p(n: mpz_r, c: ui_t, d: ui_t) -> bool {
1741  unsafe { __gmpz_congruent_ui_p(n, c, d) != 0 }
1742}
1743
1744/// mpz_congruent_2exp_p
1745pub fn mpz_congruent_2exp_p(n: mpz_r, c: mpz_r, b: mp_bitcnt_t) -> bool {
1746  unsafe { __gmpz_congruent_2exp_p(n, c, b) != 0 }
1747}
1748
1749/// mpz_powm_sec c = (a**n) mod m ***required n &gt; 0 and m is odd***
1750pub fn mpz_powm_sec(c: mpz_t, a: mpz_r, n: mpz_r, m: mpz_r) -> () {
1751  unsafe { __gmpz_powm_sec(c, a, n, m) }
1752}
1753
1754/// mpz_powm c = (a**n) mod m ***n &lt; 0 when exists inv a**-1 mod m***
1755pub fn mpz_powm(c: mpz_t, a: mpz_r, n: mpz_r, m: mpz_r) -> () {
1756  unsafe { __gmpz_powm(c, a, n, m) }
1757}
1758
1759/// mpz_powm_ui c = (a**n) mod m
1760pub fn mpz_powm_ui(c: mpz_t, a: mpz_r, n: ui_t, m: mpz_r) -> () {
1761  unsafe { __gmpz_powm_ui(c, a, n, m) }
1762}
1763
1764/// mpz_pow_ui c == a**n
1765pub fn mpz_pow_ui(c: mpz_t, a: mpz_r, n: ui_t) -> () {
1766  unsafe { __gmpz_pow_ui(c, a, n) }
1767}
1768
1769/// mpz_ui_pow_ui c = a**n
1770pub fn mpz_ui_pow_ui(c: mpz_t, a: ui_t, n: ui_t) -> () {
1771  unsafe { __gmpz_ui_pow_ui(c, a, n) }
1772}
1773
1774/// mpz_sizeinbase
1775pub fn mpz_sizeinbase(a: mpz_r, base: int_t) -> mp_size_t {
1776  unsafe { __gmpz_sizeinbase(a, base) }
1777}
1778
1779/// mpz_even_p
1780pub fn mpz_even_p(a: mpz_r) -> bool {
1781/*
1782  unsafe { __gmpz_even_p(a) != 0 }
1783*/
1784  !mpz_odd_p(a)
1785}
1786
1787/// mpz_odd_p
1788pub fn mpz_odd_p(a: mpz_r) -> bool {
1789/*
1790  unsafe { __gmpz_odd_p(a) != 0 }
1791*/
1792unsafe {
1793  a._mp_size != 0 && (1 & std::slice::from_raw_parts(a._mp_d, 1)[0]) != 0
1794}
1795}
1796
1797/// mpz_fits_ulong_p
1798pub fn mpz_fits_ulong_p(a: mpz_r) -> bool {
1799  unsafe { __gmpz_fits_ulong_p(a) != 0 }
1800}
1801
1802/// mpz_fits_slong_p
1803pub fn mpz_fits_slong_p(a: mpz_r) -> bool {
1804  unsafe { __gmpz_fits_slong_p(a) != 0 }
1805}
1806
1807/// mpz_fits_uint_p
1808pub fn mpz_fits_uint_p(a: mpz_r) -> bool {
1809  unsafe { __gmpz_fits_uint_p(a) != 0 }
1810}
1811
1812/// mpz_fits_sint_p
1813pub fn mpz_fits_sint_p(a: mpz_r) -> bool {
1814  unsafe { __gmpz_fits_sint_p(a) != 0 }
1815}
1816
1817/// mpz_fits_ushort_p
1818pub fn mpz_fits_ushort_p(a: mpz_r) -> bool {
1819  unsafe { __gmpz_fits_ushort_p(a) != 0 }
1820}
1821
1822/// mpz_fits_sshort_p
1823pub fn mpz_fits_sshort_p(a: mpz_r) -> bool {
1824  unsafe { __gmpz_fits_sshort_p(a) != 0 }
1825}
1826
1827/// mpz_urandomb
1828pub fn mpz_urandomb(c: mpz_t, r: randstate_t, nbits: mp_bitcnt_t) -> () {
1829  unsafe { __gmpz_urandomb(c, r, nbits) }
1830}
1831
1832/// mpz_urandomm
1833pub fn mpz_urandomm(c: mpz_t, r: randstate_t, n: mpz_r) -> () {
1834  unsafe { __gmpz_urandomm(c, r, n) }
1835}
1836
1837/// mpz_rrandomb
1838pub fn mpz_rrandomb(c: mpz_t, r: randstate_t, nbits: mp_bitcnt_t) -> () {
1839  unsafe { __gmpz_rrandomb(c, r, nbits) }
1840}
1841
1842/// mpz_random ***(obsoleted) use mpz_urandomb or mpz_urandomm instead***
1843pub fn mpz_random(c: mpz_t, max_size: mp_size_t) -> () {
1844  unsafe { __gmpz_random(c, max_size) }
1845}
1846
1847/// mpz_random2
1848pub fn mpz_random2(c: mpz_t, max_size: mp_size_t) -> () {
1849  unsafe { __gmpz_random2(c, max_size) }
1850}
1851
1852/// mpz_and
1853pub fn mpz_and(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1854  unsafe { __gmpz_and(c, a, b) }
1855}
1856
1857/// mpz_ior
1858pub fn mpz_ior(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1859  unsafe { __gmpz_ior(c, a, b) }
1860}
1861
1862/// mpz_xor
1863pub fn mpz_xor(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1864  unsafe { __gmpz_xor(c, a, b) }
1865}
1866
1867/// mpz_com
1868pub fn mpz_com(c: mpz_t, a: mpz_r) -> () {
1869  unsafe { __gmpz_com(c, a) }
1870}
1871
1872/// mpz_popcount
1873pub fn mpz_popcount(a: mpz_r) -> mp_bitcnt_t {
1874  unsafe { __gmpz_popcount(a) }
1875}
1876
1877/// mpz_hamdist hamming distance between a and b (both sgn must be same)
1878pub fn mpz_hamdist(a: mpz_r, b: mpz_r) -> mp_bitcnt_t {
1879  unsafe { __gmpz_hamdist(a, b) }
1880}
1881
1882/// mpz_scan0 to msb
1883pub fn mpz_scan0(a: mpz_r, s: mp_bitcnt_t) -> mp_bitcnt_t {
1884  unsafe { __gmpz_scan0(a, s) }
1885}
1886
1887/// mpz_scan1 to msb
1888pub fn mpz_scan1(a: mpz_r, s: mp_bitcnt_t) -> mp_bitcnt_t {
1889  unsafe { __gmpz_scan1(a, s) }
1890}
1891
1892/// mpz_clrbit
1893pub fn mpz_clrbit(c: mpz_t, n: mp_bitcnt_t) -> () {
1894  unsafe { __gmpz_clrbit(c, n) }
1895}
1896
1897/// mpz_setbit
1898pub fn mpz_setbit(c: mpz_t, n: mp_bitcnt_t) -> () {
1899  unsafe { __gmpz_setbit(c, n) }
1900}
1901
1902/// mpz_combit
1903pub fn mpz_combit(c: mpz_t, n: mp_bitcnt_t) -> () {
1904  unsafe { __gmpz_combit(c, n) }
1905}
1906
1907/// mpz_tstbit
1908pub fn mpz_tstbit(a: mpz_r, n: mp_bitcnt_t) -> bool {
1909  unsafe { __gmpz_tstbit(a, n) != 0 }
1910}