1use std::fmt;
5use std::error::Error;
6use std::collections::HashMap;
7
8use crate::prim::{*, typ::*, randstate::*, gmp::*}; #[repr(C)]
13pub struct __mpz_struct {
14 pub _mp_alloc: int_t,
16 pub _mp_size: int_t,
18 pub _mp_d: *mut mp_limb_t
20}
21
22impl SNew for __mpz_struct {
24 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
34impl Drop for __mpz_struct {
36 fn drop(&mut self) {
37 self.clear()
38 }
39}
40
41impl __mpz_struct {
43 pub fn clear(&mut self) -> () {
45 mpz_clear(self)
46 }
47
48 pub fn init() -> Self {
50 let mut t = mpz_s::new();
51 mpz_init(&mut t);
52 t
53 }
54
55 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 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 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 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 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 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 pub fn set(&mut self, a: mpz_r) -> &mut Self {
99 mpz_set(self, a);
100 self
101 }
102
103 pub fn set_ui(&mut self, u: ui_t) -> &mut Self {
105 mpz_set_ui(self, u);
106 self
107 }
108
109 pub fn set_si(&mut self, s: si_t) -> &mut Self {
111 mpz_set_si(self, s);
112 self
113 }
114
115 pub fn set_d(&mut self, d: double_t) -> &mut Self {
117 mpz_set_d(self, d);
118 self
119 }
120
121 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 pub fn fmtstr(&self, b: int_t) -> String {
129 mpz_get_str(None, b, self).expect("mpz fmtstr")
130 }
131
132 pub fn binstr(&self) -> String {
135 mpz_get_str(None, 2, self).expect("mpz binstr")
136 }
137
138 pub fn hexstr(&self) -> String {
141 mpz_get_str(None, 16, self).expect("mpz hexstr")
142 }
143
144 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))); s.join(" ")
151 }
152
153 pub fn get_d(&self) -> double_t {
155 mpz_get_d(self)
156 }
157
158 pub fn get_ui(&self) -> ui_t {
160 mpz_get_ui(self)
161 }
162
163 pub fn get_si(&self) -> si_t {
165 mpz_get_si(self)
166 }
167
168 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 pub fn swap(&mut self, b: mpz_t) -> &mut Self {
177 mpz_swap(self, b);
178 self
179 }
180
181 pub fn realloc2(&mut self, n: mp_bitcnt_t) -> &mut Self {
183 mpz_realloc2(self, n);
184 self
185 }
186
187 pub fn _realloc(&mut self, sz: mp_size_t) -> &mut Self {
189 _mpz_realloc(self, sz);
190 self
191 }
192
193 pub fn size(&self) -> mp_size_t {
195 mpz_size(self)
196 }
197
198 pub fn limbs_read(&self) -> &[mp_limb_t] {
200 mpz_limbs_read(self)
201 }
202
203 pub fn getlimbn(&self, n: mp_size_t) -> mp_limb_t {
205 mpz_getlimbn(self, n)
206 }
207
208 pub fn limbs_write(&mut self, sz: mp_size_t) -> &mut [mp_limb_t] {
210 mpz_limbs_write(self, sz)
211 }
212
213 pub fn limbs_modify(&mut self, sz: mp_size_t) -> &mut [mp_limb_t] {
215 mpz_limbs_modify(self, sz)
216 }
217
218 pub fn limbs_finish(&mut self, sz: mp_size_t) -> &mut Self {
220 mpz_limbs_finish(self, sz);
221 self
222 }
223
224 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 pub fn cmp(&self, b: mpz_r) -> int_t {
231 mpz_cmp(self, b)
232 }
233
234 pub fn cmp_d(&self, d: double_t) -> int_t {
236 mpz_cmp_d(self, d)
237 }
238
239 pub fn cmp_ui(&self, u: ui_t) -> int_t {
241 mpz_cmp_ui(self, u)
242 }
243
244 pub fn cmp_si(&self, s: si_t) -> int_t {
246 mpz_cmp_si(self, s)
247 }
248
249 pub fn cmpabs(&self, b: mpz_r) -> int_t {
251 mpz_cmpabs(self, b)
252 }
253
254 pub fn cmpabs_d(&self, d: double_t) -> int_t {
256 mpz_cmpabs_d(self, d)
257 }
258
259 pub fn cmpabs_ui(&self, u: ui_t) -> int_t {
261 mpz_cmpabs_ui(self, u)
262 }
263
264 pub fn sgn(&self) -> int_t {
266 mpz_sgn(self)
267 }
268
269 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 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 pub fn sqrt(&self) -> Self {
286 let mut t = mpz_s::init();
287 mpz_sqrt(&mut t, self);
288 t
289 }
290
291 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 pub fn perfect_power_p(&self) -> bool {
301 mpz_perfect_power_p(self)
302 }
303
304 pub fn perfect_square_p(&self) -> bool {
306 mpz_perfect_square_p(self)
307 }
308
309 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 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 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 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 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 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 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 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 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 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 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 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 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 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 pub fn probab_prime_p(&self, r: int_t) -> int_t {
415 mpz_probab_prime_p(self, r)
416 }
417
418 pub fn nextprime(&self) -> Self {
420 let mut t = mpz_s::init();
421 mpz_nextprime(&mut t, self);
422 t
423 }
424
425pub 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 pub fn jacobi(&self, n: mpz_r) -> int_t {
444 mpz_jacobi(self, n)
445 }
446
447 pub fn legendre(&self, p: mpz_r) -> int_t {
449 mpz_legendre(self, p)
450 }
451
452 pub fn kronecker(&self, n: mpz_r) -> int_t {
454 mpz_kronecker(self, n)
455 }
456
457 pub fn kronecker_ui(&self, u: ui_t) -> int_t {
459 mpz_kronecker_ui(self, u)
460 }
461
462 pub fn kronecker_si(&self, s: si_t) -> int_t {
464 mpz_kronecker_si(self, s)
465 }
466
467 pub fn ui_kronecker(&self, u: ui_t) -> int_t {
469 mpz_ui_kronecker(u, self)
470 }
471
472 pub fn si_kronecker(&self, s: si_t) -> int_t {
474 mpz_si_kronecker(s, self)
475 }
476
477 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 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 pub fn abs(&self) -> Self {
493 let mut t = mpz_s::new();
494 mpz_abs(&mut t, self);
495 t
496 }
497
498 pub fn neg(&self) -> Self {
500 let mut t = mpz_s::new();
501 mpz_neg(&mut t, self);
502 t
503 }
504
505 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 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 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 pub fn submul(&mut self, a: mpz_r, b: mpz_r) -> &mut Self {
525 mpz_submul(self, a, b);
526 self
527 }
528
529 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 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 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 pub fn addmul(&mut self, a: mpz_r, b: mpz_r) -> &mut Self {
549 mpz_addmul(self, a, b);
550 self
551 }
552
553 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 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 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 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 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 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 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 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 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 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 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 pub fn cdiv_ui(&self, d: ui_t) -> ui_t {
629 mpz_cdiv_ui(self, d)
630 }
631
632 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 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 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 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 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 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 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 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 pub fn fdiv_ui(&self, d: ui_t) -> ui_t {
692 mpz_fdiv_ui(self, d)
693 }
694
695 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 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 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 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 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 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 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 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 pub fn tdiv_ui(&self, d: ui_t) -> ui_t {
755 mpz_tdiv_ui(self, d)
756 }
757
758 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 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 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 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 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 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 pub fn divisible_p(&self, d: mpz_r) -> bool {
802 mpz_divisible_p(self, d)
803 }
804
805 pub fn divisible_ui_p(&self, d: ui_t) -> bool {
807 mpz_divisible_ui_p(self, d)
808 }
809
810 pub fn divisible_2exp_p(&self, b: mp_bitcnt_t) -> bool {
812 mpz_divisible_2exp_p(self, b)
813 }
814
815 pub fn congruent_p(&self, c: mpz_r, d: mpz_r) -> bool {
817 mpz_congruent_p(self, c, d)
818 }
819
820 pub fn congruent_ui_p(&self, c: ui_t, d: ui_t) -> bool {
822 mpz_congruent_ui_p(self, c, d)
823 }
824
825 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 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 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 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 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 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 pub fn sizeinbase(&self, base: int_t) -> mp_size_t {
867 mpz_sizeinbase(self, base)
868 }
869
870 pub fn even_p(&self) -> bool {
872 mpz_even_p(self)
873 }
874
875 pub fn odd_p(&self) -> bool {
877 mpz_odd_p(self)
878 }
879
880 pub fn fits_ulong_p(&self) -> bool {
882 mpz_fits_ulong_p(self)
883 }
884
885 pub fn fits_slong_p(&self) -> bool {
887 mpz_fits_slong_p(self)
888 }
889
890 pub fn fits_uint_p(&self) -> bool {
892 mpz_fits_uint_p(self)
893 }
894
895 pub fn fits_sint_p(&self) -> bool {
897 mpz_fits_sint_p(self)
898 }
899
900 pub fn fits_ushort_p(&self) -> bool {
902 mpz_fits_ushort_p(self)
903 }
904
905 pub fn fits_sshort_p(&self) -> bool {
907 mpz_fits_sshort_p(self)
908 }
909
910 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 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 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 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 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 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 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 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 pub fn com(&self) -> Self {
968 let mut t = mpz_s::init();
969 mpz_com(&mut t, self);
970 t
971 }
972
973 pub fn popcount(&self) -> mp_bitcnt_t {
975 mpz_popcount(self)
976 }
977
978 pub fn hamdist(&self, b: mpz_r) -> mp_bitcnt_t {
980 mpz_hamdist(self, b)
981 }
982
983 pub fn scan0(&self, s: mp_bitcnt_t) -> mp_bitcnt_t {
985 mpz_scan0(self, s)
986 }
987
988 pub fn scan1(&self, s: mp_bitcnt_t) -> mp_bitcnt_t {
990 mpz_scan1(self, s)
991 }
992
993 pub fn clrbit(&mut self, n: mp_bitcnt_t) -> &mut Self {
995 mpz_clrbit(self, n);
996 self
997 }
998
999 pub fn setbit(&mut self, n: mp_bitcnt_t) -> &mut Self {
1001 mpz_setbit(self, n);
1002 self
1003 }
1004
1005 pub fn combit(&mut self, n: mp_bitcnt_t) -> &mut Self {
1007 mpz_combit(self, n);
1008 self
1009 }
1010
1011 pub fn tstbit(&self, n: mp_bitcnt_t) -> bool {
1013 mpz_tstbit(self, n)
1014 }
1015
1016 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 pub fn fact_cached(n: ui_t, m: &mut HashMap<ui_t, mpz_s>) -> Self {
1025if let Some(e) = m.get_mut(&n) { return mpz_s::init_set(e); } 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)); e
1037 }
1038}
1039
1040impl fmt::Debug for __mpz_struct {
1042 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
1053impl fmt::Display for __mpz_struct {
1055 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1057 write!(f, "{}", self.fmtstr(10))
1058 }
1059}
1060
1061#[allow(non_camel_case_types)]
1063pub type mpz_s = __mpz_struct; #[allow(non_camel_case_types)]
1066pub type mpz_t<'a> = &'a mut mpz_s; #[allow(non_camel_case_types)]
1069pub type mpz_r<'a> = &'a mpz_s; pub fn mpz_clears(va: &mut Vec<mpz_t>) -> () {
1073 va.iter_mut().for_each(|a| {
1074 unsafe { __gmpz_clear(*a) } })
1076}
1077
1078pub fn mpz_clear(a: mpz_t) -> () {
1080 unsafe { __gmpz_clear(a) }
1081}
1082
1083pub fn mpz_inits(va: &mut Vec<mpz_t>) -> () {
1085 va.iter_mut().for_each(|a| {
1086 unsafe { __gmpz_init(*a) } })
1088}
1089
1090pub fn mpz_init(a: mpz_t) -> () {
1092 unsafe { __gmpz_init(a) }
1093}
1094
1095pub fn mpz_init2(a: mpz_t, n: mp_bitcnt_t) -> () {
1097 unsafe { __gmpz_init2(a, n) }
1098}
1099
1100pub fn mpz_init_set(a: mpz_t, b: mpz_r) -> () {
1102 unsafe { __gmpz_init_set(a, b) }
1103}
1104
1105pub fn mpz_init_set_ui(a: mpz_t, u: ui_t) -> () {
1107 unsafe { __gmpz_init_set_ui(a, u) }
1108}
1109
1110pub fn mpz_init_set_si(a: mpz_t, s: si_t) -> () {
1112 unsafe { __gmpz_init_set_si(a, s) }
1113}
1114
1115pub fn mpz_init_set_d(a: mpz_t, d: double_t) -> () {
1117 unsafe { __gmpz_init_set_d(a, d) }
1118}
1119
1120pub 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
1125pub 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
1130pub fn mpz_set(a: mpz_t, b: mpz_r) -> () {
1132 unsafe { __gmpz_set(a, b) }
1133}
1134
1135pub fn mpz_set_ui(a: mpz_t, u: ui_t) -> () {
1137 unsafe { __gmpz_set_ui(a, u) }
1138}
1139
1140pub fn mpz_set_si(a: mpz_t, s: si_t) -> () {
1142 unsafe { __gmpz_set_si(a, s) }
1143}
1144
1145pub fn mpz_set_d(a: mpz_t, d: double_t) -> () {
1147 unsafe { __gmpz_set_d(a, d) }
1148}
1149
1150pub fn mpz_set_str(a: mpz_t, s: &str, b: int_t) -> () {
1152 mpz_set_str_u8z(a, to_u8z!(s), b)
1153}
1154
1155pub 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
1160pub 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
1172pub 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
1185pub fn mpz_get_d(a: mpz_r) -> double_t {
1187 unsafe { __gmpz_get_d(a) }
1188}
1189
1190pub fn mpz_get_ui(a: mpz_r) -> ui_t {
1192 unsafe { __gmpz_get_ui(a) }
1193}
1194
1195pub fn mpz_get_si(a: mpz_r) -> si_t {
1197 unsafe { __gmpz_get_si(a) }
1198}
1199
1200pub fn mpz_get_d_2exp(e: &mut si_t, a: mpz_r) -> double_t {
1202 unsafe { __gmpz_get_d_2exp(e, a) }
1203}
1204
1205pub fn mpz_swap(a: mpz_t, b: mpz_t) -> () {
1207 unsafe { __gmpz_swap(a, b) }
1208}
1209
1210pub fn mpz_realloc2(a: mpz_t, n: mp_bitcnt_t) -> () {
1212 unsafe { __gmpz_realloc2(a, n) }
1213}
1214
1215pub fn _mpz_realloc(a: mpz_t, sz: mp_size_t) -> mp_t {
1217 unsafe { __gmpz_realloc(a, sz) }
1218}
1219
1220pub 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
1225pub fn mpz_size(a: mpz_r) -> mp_size_t {
1227 unsafe { __gmpz_size(a) }
1228}
1229
1230pub 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
1236pub fn mpz_getlimbn(a: mpz_r, n: mp_size_t) -> mp_limb_t {
1238 unsafe { __gmpz_getlimbn(a, n) }
1239}
1240
1241pub 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
1246pub 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
1251pub fn mpz_limbs_finish(a: mpz_t, sz: mp_size_t) -> () {
1253 unsafe { __gmpz_limbs_finish(a, sz) }
1254}
1255
1256pub 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#[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
1276pub fn mpz_cmp(a: mpz_r, b: mpz_r) -> int_t {
1278 unsafe { __gmpz_cmp(a, b) }
1279}
1280
1281pub fn mpz_cmp_d(a: mpz_r, d: double_t) -> int_t {
1283 unsafe { __gmpz_cmp_d(a, d) }
1284}
1285
1286pub fn mpz_cmp_ui(a: mpz_r, u: ui_t) -> int_t {
1288 unsafe { __gmpz_cmp_ui(a, u) }
1289}
1290
1291pub fn mpz_cmp_si(a: mpz_r, s: si_t) -> int_t {
1293 unsafe { __gmpz_cmp_si(a, s) }
1294}
1295
1296pub fn mpz_cmpabs(a: mpz_r, b: mpz_r) -> int_t {
1298 unsafe { __gmpz_cmpabs(a, b) }
1299}
1300
1301pub fn mpz_cmpabs_d(a: mpz_r, d: double_t) -> int_t {
1303 unsafe { __gmpz_cmpabs_d(a, d) }
1304}
1305
1306pub fn mpz_cmpabs_ui(a: mpz_r, u: ui_t) -> int_t {
1308 unsafe { __gmpz_cmpabs_ui(a, u) }
1309}
1310
1311pub fn mpz_sgn(a: mpz_r) -> int_t {
1313let t = a._mp_size;
1315 if t < 0 { -1 } else { if t > 0 { 1 } else { 0 } }
1316}
1317
1318pub fn mpz_root(r: mpz_t, a: mpz_r, n: ui_t) -> bool {
1320 unsafe { __gmpz_root(r, a, n) != 0 }
1321}
1322
1323pub 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
1328pub fn mpz_sqrt(r: mpz_t, a: mpz_r) -> () {
1330 unsafe { __gmpz_sqrt(r, a) }
1331}
1332
1333pub fn mpz_sqrtrem(r: mpz_t, rem: mpz_t, u: mpz_r) -> () {
1335 unsafe { __gmpz_sqrtrem(r, rem, u) }
1336}
1337
1338pub fn mpz_perfect_power_p(a: mpz_r) -> bool {
1340 unsafe { __gmpz_perfect_power_p(a) != 0 }
1341}
1342
1343pub fn mpz_perfect_square_p(a: mpz_r) -> bool {
1345 unsafe { __gmpz_perfect_square_p(a) != 0 }
1346}
1347
1348pub fn mpz_primorial_ui(c: mpz_t, n: ui_t) -> () {
1350 unsafe { __gmpz_primorial_ui(c, n) }
1351}
1352
1353pub fn mpz_fac_ui(c: mpz_t, n: ui_t) -> () {
1355 unsafe { __gmpz_fac_ui(c, n) }
1356}
1357
1358pub fn mpz_2fac_ui(c: mpz_t, n: ui_t) -> () {
1360 unsafe { __gmpz_2fac_ui(c, n) }
1361}
1362
1363pub fn mpz_mfac_uiui(c: mpz_t, n: ui_t, m: ui_t) -> () {
1365 unsafe { __gmpz_mfac_uiui(c, n, m) }
1366}
1367
1368pub fn mpz_remove(c: mpz_t, a: mpz_r, f: mpz_r) -> mp_bitcnt_t {
1370 unsafe { __gmpz_remove(c, a, f) }
1371}
1372
1373pub fn mpz_fib_ui(f_n: mpz_t, n: ui_t) -> () {
1375 unsafe { __gmpz_fib_ui(f_n, n) }
1376}
1377
1378pub 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
1383pub fn mpz_lucnum_ui(l_n: mpz_t, n: ui_t) -> () {
1385 unsafe { __gmpz_lucnum_ui(l_n, n) }
1386}
1387
1388pub 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
1393pub fn mpz_gcd(g: mpz_t, a: mpz_r, b: mpz_r) -> () {
1395 unsafe { __gmpz_gcd(g, a, b) }
1396}
1397
1398pub 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
1403pub 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
1408pub fn mpz_lcm(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1410 unsafe { __gmpz_lcm(c, a, b) }
1411}
1412
1413pub fn mpz_lcm_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1415 unsafe { __gmpz_lcm_ui(c, a, u) }
1416}
1417
1418pub fn mpz_probab_prime_p(a: mpz_r, r: int_t) -> int_t {
1420 unsafe { __gmpz_probab_prime_p(a, r) }
1421}
1422
1423pub fn mpz_nextprime(c: mpz_t, a: mpz_r) -> () {
1425 unsafe { __gmpz_nextprime(c, a) }
1426}
1427
1428pub fn mpz_invert(c: mpz_t, a: mpz_r, b: mpz_r) -> int_t {
1437 unsafe { __gmpz_invert(c, a, b) }
1438}
1439
1440pub fn mpz_jacobi(a: mpz_r, n: mpz_r) -> int_t {
1442 unsafe { __gmpz_jacobi(a, n) }
1443}
1444
1445pub fn mpz_legendre(a: mpz_r, p: mpz_r) -> int_t {
1447 unsafe { __gmpz_legendre(a, p) }
1448}
1449
1450pub fn mpz_kronecker(a: mpz_r, n: mpz_r) -> int_t {
1452unsafe { __gmpz_jacobi(a, n) }
1456}
1457
1458pub fn mpz_kronecker_ui(a: mpz_r, u: ui_t) -> int_t {
1460 unsafe { __gmpz_kronecker_ui(a, u) }
1461}
1462
1463pub fn mpz_kronecker_si(a: mpz_r, s: si_t) -> int_t {
1465 unsafe { __gmpz_kronecker_si(a, s) }
1466}
1467
1468pub fn mpz_ui_kronecker(u: ui_t, a: mpz_r) -> int_t {
1470 unsafe { __gmpz_ui_kronecker(u, a) }
1471}
1472
1473pub fn mpz_si_kronecker(s: si_t, a: mpz_r) -> int_t {
1475 unsafe { __gmpz_si_kronecker(s, a) }
1476}
1477
1478pub fn mpz_bin_ui(c: mpz_t, n: mpz_r, k: ui_t) -> () {
1480 unsafe { __gmpz_bin_ui(c, n, k) }
1481}
1482
1483pub fn mpz_bin_uiui(c: mpz_t, n: ui_t, k: ui_t) -> () {
1485 unsafe { __gmpz_bin_uiui(c, n, k) }
1486}
1487
1488pub fn mpz_abs(c: mpz_t, a: mpz_r) -> () {
1490 unsafe { __gmpz_abs(c, a) }
1491}
1492
1493pub fn mpz_neg(c: mpz_t, a: mpz_r) -> () {
1495 unsafe { __gmpz_neg(c, a) }
1496}
1497
1498pub fn mpz_sub(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1500 unsafe { __gmpz_sub(c, a, b) }
1501}
1502
1503pub fn mpz_sub_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1505 unsafe { __gmpz_sub_ui(c, a, u) }
1506}
1507
1508pub fn mpz_ui_sub(c: mpz_t, u: ui_t, a: mpz_r) -> () {
1510 unsafe { __gmpz_ui_sub(c, u, a) }
1511}
1512
1513pub fn mpz_submul(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1515 unsafe { __gmpz_submul(c, a, b) }
1516}
1517
1518pub fn mpz_submul_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1520 unsafe { __gmpz_submul_ui(c, a, u) }
1521}
1522
1523pub fn mpz_add(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1525 unsafe { __gmpz_add(c, a, b) }
1526}
1527
1528pub fn mpz_add_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1530 unsafe { __gmpz_add_ui(c, a, u) }
1531}
1532
1533pub fn mpz_addmul(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1535 unsafe { __gmpz_addmul(c, a, b) }
1536}
1537
1538pub fn mpz_addmul_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1540 unsafe { __gmpz_addmul_ui(c, a, u) }
1541}
1542
1543pub fn mpz_mul(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1545 unsafe { __gmpz_mul(c, a, b) }
1546}
1547
1548pub fn mpz_mul_ui(c: mpz_t, a: mpz_r, u: ui_t) -> () {
1550 unsafe { __gmpz_mul_ui(c, a, u) }
1551}
1552
1553pub fn mpz_mul_si(c: mpz_t, a: mpz_r, s: si_t) -> () {
1555 unsafe { __gmpz_mul_si(c, a, s) }
1556}
1557
1558pub fn mpz_mul_2exp(c: mpz_t, a: mpz_r, n: mp_bitcnt_t) -> () {
1560 unsafe { __gmpz_mul_2exp(c, a, n) }
1561}
1562
1563pub fn mpz_cdiv_q(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1565 unsafe { __gmpz_cdiv_q(q, n, d) }
1566}
1567
1568pub fn mpz_cdiv_r(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1570 unsafe { __gmpz_cdiv_r(r, n, d) }
1571}
1572
1573pub 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
1578pub 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
1583pub 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
1588pub 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
1593pub fn mpz_cdiv_ui(n: mpz_r, d: ui_t) -> ui_t {
1595 unsafe { __gmpz_cdiv_ui(n, d) }
1596}
1597
1598pub 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
1603pub 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
1608pub fn mpz_fdiv_q(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1610 unsafe { __gmpz_fdiv_q(q, n, d) }
1611}
1612
1613pub fn mpz_fdiv_r(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1615 unsafe { __gmpz_fdiv_r(r, n, d) }
1616}
1617
1618pub 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
1623pub 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
1628pub 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
1633pub 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
1638pub fn mpz_fdiv_ui(n: mpz_r, d: ui_t) -> ui_t {
1640 unsafe { __gmpz_fdiv_ui(n, d) }
1641}
1642
1643pub 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
1648pub 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
1653pub fn mpz_tdiv_q(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1655 unsafe { __gmpz_tdiv_q(q, n, d) }
1656}
1657
1658pub fn mpz_tdiv_r(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1660 unsafe { __gmpz_tdiv_r(r, n, d) }
1661}
1662
1663pub 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
1668pub 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
1673pub 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
1678pub 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
1683pub fn mpz_tdiv_ui(n: mpz_r, d: ui_t) -> ui_t {
1685 unsafe { __gmpz_tdiv_ui(n, d) }
1686}
1687
1688pub 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
1693pub 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
1698pub fn mpz_mod(r: mpz_t, n: mpz_r, d: mpz_r) -> () {
1700 unsafe { __gmpz_mod(r, n, d) }
1701}
1702
1703pub fn mpz_mod_ui(r: mpz_t, n: mpz_r, d: ui_t) -> ui_t {
1705unsafe { __gmpz_fdiv_r_ui(r, n, d) }
1707}
1708
1709pub fn mpz_divexact(q: mpz_t, n: mpz_r, d: mpz_r) -> () {
1711 unsafe { __gmpz_divexact(q, n, d) }
1712}
1713
1714pub fn mpz_divexact_ui(q: mpz_t, n: mpz_r, d: ui_t) -> () {
1716 unsafe { __gmpz_divexact_ui(q, n, d) }
1717}
1718
1719pub fn mpz_divisible_p(n: mpz_r, d: mpz_r) -> bool {
1721 unsafe { __gmpz_divisible_p(n, d) != 0 }
1722}
1723
1724pub fn mpz_divisible_ui_p(n: mpz_r, d: ui_t) -> bool {
1726 unsafe { __gmpz_divisible_ui_p(n, d) != 0 }
1727}
1728
1729pub fn mpz_divisible_2exp_p(n: mpz_r, b: mp_bitcnt_t) -> bool {
1731 unsafe { __gmpz_divisible_2exp_p(n, b) != 0 }
1732}
1733
1734pub 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
1739pub 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
1744pub 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
1749pub 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
1754pub 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
1759pub 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
1764pub fn mpz_pow_ui(c: mpz_t, a: mpz_r, n: ui_t) -> () {
1766 unsafe { __gmpz_pow_ui(c, a, n) }
1767}
1768
1769pub 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
1774pub fn mpz_sizeinbase(a: mpz_r, base: int_t) -> mp_size_t {
1776 unsafe { __gmpz_sizeinbase(a, base) }
1777}
1778
1779pub fn mpz_even_p(a: mpz_r) -> bool {
1781!mpz_odd_p(a)
1785}
1786
1787pub fn mpz_odd_p(a: mpz_r) -> bool {
1789unsafe {
1793 a._mp_size != 0 && (1 & std::slice::from_raw_parts(a._mp_d, 1)[0]) != 0
1794}
1795}
1796
1797pub fn mpz_fits_ulong_p(a: mpz_r) -> bool {
1799 unsafe { __gmpz_fits_ulong_p(a) != 0 }
1800}
1801
1802pub fn mpz_fits_slong_p(a: mpz_r) -> bool {
1804 unsafe { __gmpz_fits_slong_p(a) != 0 }
1805}
1806
1807pub fn mpz_fits_uint_p(a: mpz_r) -> bool {
1809 unsafe { __gmpz_fits_uint_p(a) != 0 }
1810}
1811
1812pub fn mpz_fits_sint_p(a: mpz_r) -> bool {
1814 unsafe { __gmpz_fits_sint_p(a) != 0 }
1815}
1816
1817pub fn mpz_fits_ushort_p(a: mpz_r) -> bool {
1819 unsafe { __gmpz_fits_ushort_p(a) != 0 }
1820}
1821
1822pub fn mpz_fits_sshort_p(a: mpz_r) -> bool {
1824 unsafe { __gmpz_fits_sshort_p(a) != 0 }
1825}
1826
1827pub fn mpz_urandomb(c: mpz_t, r: randstate_t, nbits: mp_bitcnt_t) -> () {
1829 unsafe { __gmpz_urandomb(c, r, nbits) }
1830}
1831
1832pub fn mpz_urandomm(c: mpz_t, r: randstate_t, n: mpz_r) -> () {
1834 unsafe { __gmpz_urandomm(c, r, n) }
1835}
1836
1837pub fn mpz_rrandomb(c: mpz_t, r: randstate_t, nbits: mp_bitcnt_t) -> () {
1839 unsafe { __gmpz_rrandomb(c, r, nbits) }
1840}
1841
1842pub fn mpz_random(c: mpz_t, max_size: mp_size_t) -> () {
1844 unsafe { __gmpz_random(c, max_size) }
1845}
1846
1847pub fn mpz_random2(c: mpz_t, max_size: mp_size_t) -> () {
1849 unsafe { __gmpz_random2(c, max_size) }
1850}
1851
1852pub fn mpz_and(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1854 unsafe { __gmpz_and(c, a, b) }
1855}
1856
1857pub fn mpz_ior(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1859 unsafe { __gmpz_ior(c, a, b) }
1860}
1861
1862pub fn mpz_xor(c: mpz_t, a: mpz_r, b: mpz_r) -> () {
1864 unsafe { __gmpz_xor(c, a, b) }
1865}
1866
1867pub fn mpz_com(c: mpz_t, a: mpz_r) -> () {
1869 unsafe { __gmpz_com(c, a) }
1870}
1871
1872pub fn mpz_popcount(a: mpz_r) -> mp_bitcnt_t {
1874 unsafe { __gmpz_popcount(a) }
1875}
1876
1877pub fn mpz_hamdist(a: mpz_r, b: mpz_r) -> mp_bitcnt_t {
1879 unsafe { __gmpz_hamdist(a, b) }
1880}
1881
1882pub fn mpz_scan0(a: mpz_r, s: mp_bitcnt_t) -> mp_bitcnt_t {
1884 unsafe { __gmpz_scan0(a, s) }
1885}
1886
1887pub fn mpz_scan1(a: mpz_r, s: mp_bitcnt_t) -> mp_bitcnt_t {
1889 unsafe { __gmpz_scan1(a, s) }
1890}
1891
1892pub fn mpz_clrbit(c: mpz_t, n: mp_bitcnt_t) -> () {
1894 unsafe { __gmpz_clrbit(c, n) }
1895}
1896
1897pub fn mpz_setbit(c: mpz_t, n: mp_bitcnt_t) -> () {
1899 unsafe { __gmpz_setbit(c, n) }
1900}
1901
1902pub fn mpz_combit(c: mpz_t, n: mp_bitcnt_t) -> () {
1904 unsafe { __gmpz_combit(c, n) }
1905}
1906
1907pub fn mpz_tstbit(a: mpz_r, n: mp_bitcnt_t) -> bool {
1909 unsafe { __gmpz_tstbit(a, n) != 0 }
1910}