-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmp.lua
1497 lines (1192 loc) · 37.1 KB
/
gmp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------
-- Binding for GNU MP v5.1.2
-----------------------------------------------------------
local ffi = require 'ffi'
local jit = require 'jit'
local header = [[
// __GMP_SHORT_LIMB
// typedef unsigned int mp_limb_t;
// typedef int mp_limb_signed_t;
// _LONG_LONG_LIMB
// typedef unsigned long long int mp_limb_t;
// typedef long long int mp_limb_signed_t;
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
typedef unsigned long int mp_bitcnt_t;
typedef mp_limb_t* mp_ptr;
typedef const mp_limb_t* mp_srcptr;
typedef int mp_size_t;
typedef int mp_exp_t;
// typedef long int mp_size_t;
// typedef long int mp_exp_t;
typedef struct
{
int _mp_alloc;
int _mp_size;
mp_limb_t* _mp_d;
} __mpz_struct;
typedef struct
{
__mpz_struct _mp_num;
__mpz_struct _mp_den;
} __mpq_struct;
typedef struct
{
int _mp_prec;
int _mp_size;
mp_exp_t _mp_exp;
mp_limb_t* _mp_d;
} __mpf_struct;
typedef __mpz_struct mpz_t[1];
typedef __mpq_struct mpq_t[1];
typedef __mpf_struct mpf_t[1];
typedef enum
{
GMP_RAND_ALG_DEFAULT = 0,
GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT
} gmp_randalg_t;
typedef struct
{
mpz_t _mp_seed;
gmp_randalg_t _mp_alg;
union {
void *_mp_lc;
} _mp_algdata;
} __gmp_randstate_struct;
typedef __gmp_randstate_struct gmp_randstate_t[1];
typedef const __mpz_struct* mpz_srcptr;
typedef __mpz_struct* mpz_ptr;
typedef const __mpf_struct* mpf_srcptr;
typedef __mpf_struct* mpf_ptr;
typedef const __mpq_struct* mpq_srcptr;
typedef __mpq_struct* mpq_ptr;
typedef void* FILE;
void __gmp_randinit_default (gmp_randstate_t);
void __gmp_randinit_lc_2exp (gmp_randstate_t, mpz_srcptr, unsigned long int, mp_bitcnt_t);
int __gmp_randinit_lc_2exp_size (gmp_randstate_t, mp_bitcnt_t);
void __gmp_randinit_mt (gmp_randstate_t);
void __gmp_randinit_set (gmp_randstate_t, const __gmp_randstate_struct *);
void __gmp_randseed (gmp_randstate_t, mpz_srcptr);
void __gmp_randseed_ui (gmp_randstate_t, unsigned long int);
void __gmp_randclear (gmp_randstate_t);
unsigned long __gmp_urandomb_ui (gmp_randstate_t, unsigned long);
unsigned long __gmp_urandomm_ui (gmp_randstate_t, unsigned long);
int __gmp_asprintf (char **, const char *, ...);
int __gmp_fprintf (FILE *, const char *, ...);
int __gmp_printf (const char *, ...);
int __gmp_snprintf (char *, size_t, const char *, ...);
int __gmp_sprintf (char *, const char *, ...);
int __gmp_fscanf (FILE *, const char *, ...);
int __gmp_scanf (const char *, ...);
int __gmp_sscanf (const char *, const char *, ...);
void *__gmpz_realloc (mpz_ptr, mp_size_t);
void __gmpz_abs (mpz_ptr, mpz_srcptr);
void __gmpz_add (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_add_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_addmul (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_addmul_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_and (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_bin_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_bin_uiui (mpz_ptr, unsigned long int, unsigned long int);
void __gmpz_cdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_cdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
unsigned long int __gmpz_cdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_cdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
unsigned long int __gmpz_cdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_cdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_cdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
unsigned long int __gmpz_cdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int);
unsigned long int __gmpz_cdiv_ui (mpz_srcptr, unsigned long int);
void __gmpz_clear (mpz_ptr);
void __gmpz_clears (mpz_ptr, ...);
void __gmpz_clrbit (mpz_ptr, mp_bitcnt_t);
int __gmpz_cmp (mpz_srcptr, mpz_srcptr);
int __gmpz_cmp_d (mpz_srcptr, double);
int __gmpz_cmp_si (mpz_srcptr, signed long int);
int __gmpz_cmp_ui (mpz_srcptr, unsigned long int);
int __gmpz_cmpabs (mpz_srcptr, mpz_srcptr);
int __gmpz_cmpabs_d (mpz_srcptr, double);
int __gmpz_cmpabs_ui (mpz_srcptr, unsigned long int);
void __gmpz_com (mpz_ptr, mpz_srcptr);
void __gmpz_combit (mpz_ptr, mp_bitcnt_t);
int __gmpz_congruent_p (mpz_srcptr, mpz_srcptr, mpz_srcptr);
int __gmpz_congruent_2exp_p (mpz_srcptr, mpz_srcptr, mp_bitcnt_t);
int __gmpz_congruent_ui_p (mpz_srcptr, unsigned long, unsigned long);
void __gmpz_divexact (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_divexact_ui (mpz_ptr, mpz_srcptr, unsigned long);
int __gmpz_divisible_p (mpz_srcptr, mpz_srcptr);
int __gmpz_divisible_ui_p (mpz_srcptr, unsigned long);
int __gmpz_divisible_2exp_p (mpz_srcptr, mp_bitcnt_t);
void __gmpz_dump (mpz_srcptr);
void *__gmpz_export (void *, size_t *, int, size_t, int, size_t, mpz_srcptr);
void __gmpz_fac_ui (mpz_ptr, unsigned long int);
void __gmpz_2fac_ui (mpz_ptr, unsigned long int);
void __gmpz_mfac_uiui (mpz_ptr, unsigned long int, unsigned long int);
void __gmpz_primorial_ui (mpz_ptr, unsigned long int);
void __gmpz_fdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_fdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
unsigned long int __gmpz_fdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_fdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
unsigned long int __gmpz_fdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_fdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_fdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
unsigned long int __gmpz_fdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int);
unsigned long int __gmpz_fdiv_ui (mpz_srcptr, unsigned long int);
void __gmpz_fib_ui (mpz_ptr, unsigned long int);
void __gmpz_fib2_ui (mpz_ptr, mpz_ptr, unsigned long int);
int __gmpz_fits_sint_p (mpz_srcptr);
int __gmpz_fits_slong_p (mpz_srcptr);
int __gmpz_fits_sshort_p (mpz_srcptr);
int __gmpz_fits_uint_p (mpz_srcptr);
int __gmpz_fits_ulong_p (mpz_srcptr);
int __gmpz_fits_ushort_p (mpz_srcptr);
void __gmpz_gcd (mpz_ptr, mpz_srcptr, mpz_srcptr);
unsigned long int __gmpz_gcd_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_gcdext (mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
double __gmpz_get_d (mpz_srcptr);
double __gmpz_get_d_2exp (signed long int *, mpz_srcptr);
long int __gmpz_get_si (mpz_srcptr);
char *__gmpz_get_str (char *, int, mpz_srcptr);
unsigned long int __gmpz_get_ui (mpz_srcptr);
mp_limb_t __gmpz_getlimbn (mpz_srcptr, mp_size_t);
mp_bitcnt_t __gmpz_hamdist (mpz_srcptr, mpz_srcptr);
void __gmpz_import (mpz_ptr, size_t, int, size_t, int, size_t, const void *);
void __gmpz_init (mpz_ptr);
void __gmpz_init2 (mpz_ptr, mp_bitcnt_t);
void __gmpz_inits (mpz_ptr, ...);
void __gmpz_init_set (mpz_ptr, mpz_srcptr);
void __gmpz_init_set_d (mpz_ptr, double);
void __gmpz_init_set_si (mpz_ptr, signed long int);
int __gmpz_init_set_str (mpz_ptr, const char *, int);
void __gmpz_init_set_ui (mpz_ptr, unsigned long int);
size_t __gmpz_inp_raw (mpz_ptr, FILE *);
size_t __gmpz_inp_str (mpz_ptr, FILE *, int);
int __gmpz_invert (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_ior (mpz_ptr, mpz_srcptr, mpz_srcptr);
int __gmpz_jacobi (mpz_srcptr, mpz_srcptr);
int __gmpz_kronecker_si (mpz_srcptr, long);
int __gmpz_kronecker_ui (mpz_srcptr, unsigned long);
int __gmpz_si_kronecker (long, mpz_srcptr);
int __gmpz_ui_kronecker (unsigned long, mpz_srcptr);
void __gmpz_lcm (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_lcm_ui (mpz_ptr, mpz_srcptr, unsigned long);
void __gmpz_lucnum_ui (mpz_ptr, unsigned long int);
void __gmpz_lucnum2_ui (mpz_ptr, mpz_ptr, unsigned long int);
int __gmpz_millerrabin (mpz_srcptr, int);
void __gmpz_mod (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_mul (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_mul_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
void __gmpz_mul_si (mpz_ptr, mpz_srcptr, long int);
void __gmpz_mul_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_neg (mpz_ptr, mpz_srcptr);
void __gmpz_nextprime (mpz_ptr, mpz_srcptr);
size_t __gmpz_out_raw (FILE *, mpz_srcptr);
size_t __gmpz_out_str (FILE *, int, mpz_srcptr);
int __gmpz_perfect_power_p (mpz_srcptr);
int __gmpz_perfect_square_p (mpz_srcptr);
mp_bitcnt_t __gmpz_popcount (mpz_srcptr);
void __gmpz_pow_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_powm (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr);
void __gmpz_powm_sec (mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr);
void __gmpz_powm_ui (mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr);
int __gmpz_probab_prime_p (mpz_srcptr, int);
void __gmpz_random (mpz_ptr, mp_size_t);
void __gmpz_random2 (mpz_ptr, mp_size_t);
void __gmpz_realloc2 (mpz_ptr, mp_bitcnt_t);
mp_bitcnt_t __gmpz_remove (mpz_ptr, mpz_srcptr, mpz_srcptr);
int __gmpz_root (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_rootrem (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_rrandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t);
mp_bitcnt_t __gmpz_scan0 (mpz_srcptr, mp_bitcnt_t);
mp_bitcnt_t __gmpz_scan1 (mpz_srcptr, mp_bitcnt_t);
void __gmpz_set (mpz_ptr, mpz_srcptr);
void __gmpz_set_d (mpz_ptr, double);
void __gmpz_set_f (mpz_ptr, mpf_srcptr);
void __gmpz_set_q (mpz_ptr, mpq_srcptr);
void __gmpz_set_si (mpz_ptr, signed long int);
int __gmpz_set_str (mpz_ptr, const char *, int);
void __gmpz_set_ui (mpz_ptr, unsigned long int);
void __gmpz_setbit (mpz_ptr, mp_bitcnt_t);
size_t __gmpz_size (mpz_srcptr);
size_t __gmpz_sizeinbase (mpz_srcptr, int);
void __gmpz_sqrt (mpz_ptr, mpz_srcptr);
void __gmpz_sqrtrem (mpz_ptr, mpz_ptr, mpz_srcptr);
void __gmpz_sub (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_sub_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_ui_sub (mpz_ptr, unsigned long int, mpz_srcptr);
void __gmpz_submul (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_submul_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_swap (mpz_ptr, mpz_ptr);
unsigned long int __gmpz_tdiv_ui (mpz_srcptr, unsigned long int);
void __gmpz_tdiv_q (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_tdiv_q_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
unsigned long int __gmpz_tdiv_q_ui (mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_tdiv_qr (mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
unsigned long int __gmpz_tdiv_qr_ui (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
void __gmpz_tdiv_r (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_tdiv_r_2exp (mpz_ptr, mpz_srcptr, mp_bitcnt_t);
unsigned long int __gmpz_tdiv_r_ui (mpz_ptr, mpz_srcptr, unsigned long int);
int __gmpz_tstbit (mpz_srcptr, mp_bitcnt_t);
void __gmpz_ui_pow_ui (mpz_ptr, unsigned long int, unsigned long int);
void __gmpz_urandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t);
void __gmpz_urandomm (mpz_ptr, gmp_randstate_t, mpz_srcptr);
void __gmpz_xor (mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpq_abs (mpq_ptr, mpq_srcptr);
void __gmpq_add (mpq_ptr, mpq_srcptr, mpq_srcptr);
void __gmpq_canonicalize (mpq_ptr);
void __gmpq_clear (mpq_ptr);
void __gmpq_clears (mpq_ptr, ...);
int __gmpq_cmp (mpq_srcptr, mpq_srcptr);
int __gmpq_cmp_si (mpq_srcptr, long, unsigned long);
int __gmpq_cmp_ui (mpq_srcptr, unsigned long int, unsigned long int);
void __gmpq_div (mpq_ptr, mpq_srcptr, mpq_srcptr);
void __gmpq_div_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t);
int __gmpq_equal (mpq_srcptr, mpq_srcptr);
void __gmpq_get_num (mpz_ptr, mpq_srcptr);
void __gmpq_get_den (mpz_ptr, mpq_srcptr);
double __gmpq_get_d (mpq_srcptr);
char *__gmpq_get_str (char *, int, mpq_srcptr);
void __gmpq_init (mpq_ptr);
void __gmpq_inits (mpq_ptr, ...);
size_t __gmpq_inp_str (mpq_ptr, FILE *, int);
void __gmpq_inv (mpq_ptr, mpq_srcptr);
void __gmpq_mul (mpq_ptr, mpq_srcptr, mpq_srcptr);
void __gmpq_mul_2exp (mpq_ptr, mpq_srcptr, mp_bitcnt_t);
void __gmpq_neg (mpq_ptr, mpq_srcptr);
size_t __gmpq_out_str (FILE *, int, mpq_srcptr);
void __gmpq_set (mpq_ptr, mpq_srcptr);
void __gmpq_set_d (mpq_ptr, double);
void __gmpq_set_den (mpq_ptr, mpz_srcptr);
void __gmpq_set_f (mpq_ptr, mpf_srcptr);
void __gmpq_set_num (mpq_ptr, mpz_srcptr);
void __gmpq_set_si (mpq_ptr, signed long int, unsigned long int);
int __gmpq_set_str (mpq_ptr, const char *, int);
void __gmpq_set_ui (mpq_ptr, unsigned long int, unsigned long int);
void __gmpq_set_z (mpq_ptr, mpz_srcptr);
void __gmpq_sub (mpq_ptr, mpq_srcptr, mpq_srcptr);
void __gmpq_swap (mpq_ptr, mpq_ptr);
void __gmpf_abs (mpf_ptr, mpf_srcptr);
void __gmpf_add (mpf_ptr, mpf_srcptr, mpf_srcptr);
void __gmpf_add_ui (mpf_ptr, mpf_srcptr, unsigned long int);
void __gmpf_ceil (mpf_ptr, mpf_srcptr);
void __gmpf_clear (mpf_ptr);
void __gmpf_clears (mpf_ptr, ...);
int __gmpf_cmp (mpf_srcptr, mpf_srcptr);
int __gmpf_cmp_d (mpf_srcptr, double);
int __gmpf_cmp_si (mpf_srcptr, signed long int);
int __gmpf_cmp_ui (mpf_srcptr, unsigned long int);
void __gmpf_div (mpf_ptr, mpf_srcptr, mpf_srcptr);
void __gmpf_div_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t);
void __gmpf_div_ui (mpf_ptr, mpf_srcptr, unsigned long int);
void __gmpf_dump (mpf_srcptr);
int __gmpf_eq (mpf_srcptr, mpf_srcptr, mp_bitcnt_t);
int __gmpf_fits_sint_p (mpf_srcptr);
int __gmpf_fits_slong_p (mpf_srcptr);
int __gmpf_fits_sshort_p (mpf_srcptr);
int __gmpf_fits_uint_p (mpf_srcptr);
int __gmpf_fits_ulong_p (mpf_srcptr);
int __gmpf_fits_ushort_p (mpf_srcptr);
void __gmpf_floor (mpf_ptr, mpf_srcptr);
double __gmpf_get_d (mpf_srcptr);
double __gmpf_get_d_2exp (signed long int *, mpf_srcptr);
mp_bitcnt_t __gmpf_get_default_prec (void);
mp_bitcnt_t __gmpf_get_prec (mpf_srcptr);
long __gmpf_get_si (mpf_srcptr);
char *__gmpf_get_str (char *, mp_exp_t *, int, size_t, mpf_srcptr);
unsigned long __gmpf_get_ui (mpf_srcptr);
void __gmpf_init (mpf_ptr);
void __gmpf_init2 (mpf_ptr, mp_bitcnt_t);
void __gmpf_inits (mpf_ptr, ...);
void __gmpf_init_set (mpf_ptr, mpf_srcptr);
void __gmpf_init_set_d (mpf_ptr, double);
void __gmpf_init_set_si (mpf_ptr, signed long int);
int __gmpf_init_set_str (mpf_ptr, const char *, int);
void __gmpf_init_set_ui (mpf_ptr, unsigned long int);
size_t __gmpf_inp_str (mpf_ptr, FILE *, int);
int __gmpf_integer_p (mpf_srcptr);
void __gmpf_mul (mpf_ptr, mpf_srcptr, mpf_srcptr);
void __gmpf_mul_2exp (mpf_ptr, mpf_srcptr, mp_bitcnt_t);
void __gmpf_mul_ui (mpf_ptr, mpf_srcptr, unsigned long int);
void __gmpf_neg (mpf_ptr, mpf_srcptr);
size_t __gmpf_out_str (FILE *, int, size_t, mpf_srcptr);
void __gmpf_pow_ui (mpf_ptr, mpf_srcptr, unsigned long int);
void __gmpf_random2 (mpf_ptr, mp_size_t, mp_exp_t);
void __gmpf_reldiff (mpf_ptr, mpf_srcptr, mpf_srcptr);
void __gmpf_set (mpf_ptr, mpf_srcptr);
void __gmpf_set_d (mpf_ptr, double);
void __gmpf_set_default_prec (mp_bitcnt_t);
void __gmpf_set_prec (mpf_ptr, mp_bitcnt_t);
void __gmpf_set_prec_raw (mpf_ptr, mp_bitcnt_t);
void __gmpf_set_q (mpf_ptr, mpq_srcptr);
void __gmpf_set_si (mpf_ptr, signed long int);
int __gmpf_set_str (mpf_ptr, const char *, int);
void __gmpf_set_ui (mpf_ptr, unsigned long int);
void __gmpf_set_z (mpf_ptr, mpz_srcptr);
size_t __gmpf_size (mpf_srcptr);
void __gmpf_sqrt (mpf_ptr, mpf_srcptr);
void __gmpf_sqrt_ui (mpf_ptr, unsigned long int);
void __gmpf_sub (mpf_ptr, mpf_srcptr, mpf_srcptr);
void __gmpf_sub_ui (mpf_ptr, mpf_srcptr, unsigned long int);
void __gmpf_swap (mpf_ptr, mpf_ptr);
void __gmpf_trunc (mpf_ptr, mpf_srcptr);
void __gmpf_ui_div (mpf_ptr, unsigned long int, mpf_srcptr);
void __gmpf_ui_sub (mpf_ptr, unsigned long int, mpf_srcptr);
void __gmpf_urandomb (mpf_t, gmp_randstate_t, mp_bitcnt_t);
]]
local bind = {}
local help = {}
local mod = {}
function mod.randinit_default(state)
bind.__gmp_randinit_default(state)
end
function mod.randinit_lc_2exp(state, a, c, m2exp)
bind.__gmp_randinit_lc_2exp(state, a, c, m2exp)
end
function mod.randinit_lc_2exp_size(state, size)
return bind.__gmp_randinit_lc_2exp_size(state, size)
end
function mod.randinit_mt(state)
bind.__gmp_randinit_mt(state)
end
function mod.randinit_set(rop, op)
bind.__gmp_randinit_set(rop, op)
end
function mod.randseed(state, seed)
bind.__gmp_randseed(state, seed)
end
function mod.randseed_ui(state, seed)
bind.__gmp_randseed_ui(state, seed)
end
function mod.randclear(state)
bind.__gmp_randclear(state)
end
function mod.urandomb_ui(state, n)
return bind.__gmp_urandomb_ui(state, n)
end
function mod.urandomm_ui(state, n)
return bind.__gmp_urandomm_ui(state, n)
end
function mod.asprintf(fmt, ...)
local pp = ffi.new('char*[1]')
local r = bind.__gmp_asprintf(pp, fmt, ...)
return pp[0], r
end
function mod.luasprintf(fmt, ...)
local pp = ffi.new('char*[1]')
local r = bind.__gmp_asprintf(pp, fmt, ...)
return ffi.string(pp[0])
end
function mod.fprintf(fp, fmt, ...)
return bind.__gmp_fprintf(fp, fmt, ...)
end
function mod.printf(fmt, ...)
return bind.__gmp_printf(fmt, ...)
end
function mod.snprintf(buf, size, fmt, ...)
if not ffi.istype('char*', bug) then
error("bad argument #1 to 'snprintf' (char* expected)", 2)
end
return bind.__gmp_snprintf(buf, size, fmt, ...)
end
function mod.sprintf(buf, fmt, ...)
if not ffi.istype('char*', bug) then
error("bad argument #1 to 'sprintf' (char* expected)", 2)
end
return bind.__gmp_sprintf(buf, fmt, ...)
end
function mod.fscanf(fp, fmt, ...)
return bind.__gmp_fscanf(fp, fmt, ...)
end
function mod.scanf(fmt, ...)
return bind.__gmp_scanf(fmt, ...)
end
function mod.sscanf(s, fmt, ...)
return bind.__gmp_sscanf(s, fmt, ...)
end
function mod.z_realloc(integer, new_alloc)
return bind.__gmpz_realloc(integer, new_alloc)
end
function mod.z_abs(rop, op)
bind.__gmpz_abs(rop, op)
end
function mod.z_add(rop, op1, op2)
bind.__gmpz_add(rop, op1, op2)
end
function mod.z_add_ui(rop, op1, op2)
bind.__gmpz_add_ui(rop, op1, op2)
end
function mod.z_addmul(rop, op1, op2)
bind.__gmpz_addmul(rop, op1, op2)
end
function mod.z_addmul_ui(rop, op1, op2)
bind.__gmpz_addmul_ui(rop, op1, op2)
end
function mod.z_and(rop, op1, op2)
bind.__gmpz_and(rop, op1, op2)
end
function mod.z_bin_ui(rop, n, k)
bind.__gmpz_bin_ui(rop, n, k)
end
function mod.z_bin_uiui(rop, n, k)
bind.__gmpz_bin_uiui(rop, n, k)
end
function mod.z_cdiv_q(q, n, d)
bind.__gmpz_cdiv_q(q, n, d)
end
function mod.z_cdiv_q_2exp(q, n, b)
bind.__gmpz_cdiv_q_2exp(q, n, b)
end
function mod.z_cdiv_q_ui(q, n, d)
return bind.__gmpz_cdiv_q_ui(q, n, d)
end
function mod.z_cdiv_qr(q, r, n, d)
bind.__gmpz_cdiv_qr(q, r, n, d)
end
function mod.z_cdiv_qr_ui(q, r, n, d)
return bind.__gmpz_cdiv_qr_ui(q, r, n, d)
end
function mod.z_cdiv_r(r, n, d)
bind.__gmpz_cdiv_r(r, n, d)
end
function mod.z_cdiv_r_2exp(r, n, b)
bind.__gmpz_cdiv_r_2exp(r, n, b)
end
function mod.z_cdiv_r_ui(r, n, d)
return bind.__gmpz_cdiv_r_ui(r, n, d)
end
function mod.z_cdiv_ui(n, d)
return bind.__gmpz_cdiv_ui(n, d)
end
function mod.z_clear(x)
bind.__gmpz_clear(x)
end
function mod.z_clears(x, ...)
bind.__gmpz_clears(x, help.vararg(...))
end
function mod.z_clrbit(rop, bit_index)
bind.__gmpz_clrbit(rop, bit_index)
end
function mod.z_cmp(op1, op2)
return bind.__gmpz_cmp(op1, op2)
end
function mod.z_cmp_d(op1, op2)
return bind.__gmpz_cmp_d(op1, op2)
end
function mod.z_cmp_si(op1, op2)
return bind.__gmpz_cmp_si(op1, op2)
end
function mod.z_cmp_ui(op1, op2)
return bind.__gmpz_cmp_ui(op1, op2)
end
function mod.z_cmpabs(op1, op2)
return bind.__gmpz_cmpabs(op1, op2)
end
function mod.z_cmpabs_d(op1, op2)
return bind.__gmpz_cmpabs_d(op1, op2)
end
function mod.z_cmpabs_ui(op1, op2)
return bind.__gmpz_cmpabs_ui(op1, op2)
end
function mod.z_com(rop, op)
bind.__gmpz_com(rop, op)
end
function mod.z_combit(rop, bit_index)
bind.__gmpz_combit(rop, bit_index)
end
function mod.z_congruent_p(n, c, d)
return bind.__gmpz_congruent_p(n, c, d)
end
function mod.z_congruent_2exp_p(n, c, b)
return bind.__gmpz_congruent_2exp_p(n, c, b)
end
function mod.z_congruent_ui_p(n, c, d)
return bind.__gmpz_congruent_ui_p(n, c, d)
end
function mod.z_divexact(q, n, d)
bind.__gmpz_divexact(q, n, d)
end
function mod.z_divexact_ui(q, n, d)
bind.__gmpz_divexact_ui(q, n, d)
end
function mod.z_divisible_p(n, d)
return bind.__gmpz_divisible_p(n, d)
end
function mod.z_divisible_ui_p(n, d)
return bind.__gmpz_divisible_ui_p(n, d)
end
function mod.z_divisible_2exp_p(n, b)
return bind.__gmpz_divisible_2exp_p(n, b)
end
function mod.z_dump(u)
bind.__gmpz_dump(u)
end
-- function mod.z_export(rop, countp, order, size, endian, nails, op)
-- -- void *__gmpz_export (void *, size_t *, int, size_t, int, size_t, mpz_srcptr)
-- return bind.__gmpz_export(rop, countp, order, size, endian, nails, op)
-- end
function mod.z_fac_ui(rop, n)
bind.__gmpz_fac_ui(rop, n)
end
function mod.z_2fac_ui(rop, n)
bind.__gmpz_2fac_ui(rop, n)
end
function mod.z_mfac_uiui(rop, n, m)
bind.__gmpz_mfac_uiui(rop, n, m)
end
function mod.z_primorial_ui(rop, n)
bind.__gmpz_primorial_ui(rop, n)
end
function mod.z_fdiv_q(q, n, d)
bind.__gmpz_fdiv_q(q, n, d)
end
function mod.z_fdiv_q_2exp(q, n, b)
bind.__gmpz_fdiv_q_2exp(q, n, b)
end
function mod.z_fdiv_q_ui(q, n, d)
return bind.__gmpz_fdiv_q_ui(q, n, d)
end
function mod.z_fdiv_qr(q, r, n, d)
bind.__gmpz_fdiv_qr(q, r, n, d)
end
function mod.z_fdiv_qr_ui(q, r, n, d)
return bind.__gmpz_fdiv_qr_ui(q, r, n, d)
end
function mod.z_fdiv_r(r, n, d)
bind.__gmpz_fdiv_r(r, n, d)
end
function mod.z_fdiv_r_2exp(r, n, b)
bind.__gmpz_fdiv_r_2exp(r, n, b)
end
function mod.z_fdiv_r_ui(r, n, d)
return bind.__gmpz_fdiv_r_ui(r, n, d)
end
function mod.z_fdiv_ui(n, d)
return bind.__gmpz_fdiv_ui(n, d)
end
function mod.z_fib_ui(fn, n)
bind.__gmpz_fib_ui(fn, n)
end
function mod.z_fib2_ui(fn, fnsub1, n)
bind.__gmpz_fib2_ui(fn, fnsub1, n)
end
function mod.z_fits_sint_p(op)
return bind.__gmpz_fits_sint_p(op)
end
function mod.z_fits_slong_p(op)
return bind.__gmpz_fits_slong_p(op)
end
function mod.z_fits_sshort_p(op)
return bind.__gmpz_fits_sshort_p(op)
end
function mod.z_fits_uint_p(op)
return bind.__gmpz_fits_uint_p(op)
end
function mod.z_fits_ulong_p(op)
return bind.__gmpz_fits_ulong_p(op)
end
function mod.z_fits_ushort_p(op)
return bind.__gmpz_fits_ushort_p(op)
end
function mod.z_gcd(rop, op1, op2)
bind.__gmpz_gcd(rop, op1, op2)
end
function mod.z_gcd_ui(rop, op1, op2)
return bind.__gmpz_gcd_ui(rop, op1, op2)
end
function mod.z_gcdext(g, s, t, a, b)
bind.__gmpz_gcdext(g, s, t, a, b)
end
function mod.z_get_d(op)
return bind.__gmpz_get_d(op)
end
function mod.z_get_d_2exp(exp, op)
return bind.__gmpz_get_d_2exp(exp, op)
end
function mod.z_get_si(op)
return bind.__gmpz_get_si(op)
end
function mod.z_get_str(str, base, op)
return ffi.string(bind.__gmpz_get_str(str, base, op))
end
function mod.z_get_ui(op)
return bind.__gmpz_get_ui(op)
end
function mod.z_getlimbn(op, n)
return bind.__gmpz_getlimbn(op, n)
end
function mod.z_hamdist(op1, op2)
return bind.__gmpz_hamdist(op1, op2)
end
-- function mod.z_import(rop, count, order, size, endian, nails, op)
-- -- void __gmpz_import (mpz_ptr, size_t, int, size_t, int, size_t, const void *)
-- bind.__gmpz_import(rop, count, order, size, endian, nails, op)
-- end
function mod.z_init(x)
bind.__gmpz_init(x)
end
function mod.z_init2(x, n)
bind.__gmpz_init2(x, n)
end
function mod.z_inits(x, ...)
bind.__gmpz_inits(x, help.vararg(...))
end
function mod.z_init_set(rop, op)
bind.__gmpz_init_set(rop, op)
end
function mod.z_init_set_d(rop, op)
bind.__gmpz_init_set_d(rop, op)
end
function mod.z_init_set_si(rop, op)
bind.__gmpz_init_set_si(rop, op)
end
function mod.z_init_set_str(rop, str, base)
return bind.__gmpz_init_set_str(rop, str, base)
end
function mod.z_init_set_ui(rop, op)
bind.__gmpz_init_set_ui(rop, op)
end
function mod.z_inp_raw(rop, stream)
return bind.__gmpz_inp_raw(rop, stream)
end
function mod.z_inp_str(rop, stream, base)
return bind.__gmpz_inp_str(rop, stream, base)
end
function mod.z_invert(rop, op1, op2)
return bind.__gmpz_invert(rop, op1, op2)
end
function mod.z_ior(rop, op1, op2)
bind.__gmpz_ior(rop, op1, op2)
end
function mod.z_jacobi(a, b)
return bind.__gmpz_jacobi(a, b)
end
function mod.z_kronecker_si(a, b)
return bind.__gmpz_kronecker_si(a, b)
end
function mod.z_kronecker_ui(a, b)
return bind.__gmpz_kronecker_ui(a, b)
end
function mod.z_si_kronecker(a, b)
return bind.__gmpz_si_kronecker(a, b)
end
function mod.z_ui_kronecker(a, b)
return bind.__gmpz_ui_kronecker(a, b)
end
function mod.z_lcm(rop, op1, op2)
bind.__gmpz_lcm(rop, op1, op2)
end
function mod.z_lcm_ui(rop, op1, op2)
bind.__gmpz_lcm_ui(rop, op1, op2)
end
function mod.z_lucnum_ui(ln, n)
bind.__gmpz_lucnum_ui(ln, n)
end
function mod.z_lucnum2_ui(ln, lnsub1, n)
bind.__gmpz_lucnum2_ui(ln, lnsub1, n)
end
function mod.z_millerrabin(n, reps)
return bind.__gmpz_millerrabin(n, reps)
end
function mod.z_mod(r, n, d)
bind.__gmpz_mod(r, n, d)
end
function mod.z_mul(rop, op1, op2)
bind.__gmpz_mul(rop, op1, op1)
end
function mod.z_mul_2exp(rop, op1, op2)
bind.__gmpz_mul_2exp(rop, op1, op2)
end
function mod.z_mul_si(rop, op1, op2)
bind.__gmpz_mul_si(rop, op1, op2)
end
function mod.z_mul_ui(rop, op1, op2)
bind.__gmpz_mul_ui(rop, op1, op2)
end
function mod.z_neg(rop, op)
bind.__gmpz_neg(rop, op)
end
function mod.z_nextprime(rop, op)
bind.__gmpz_nextprime(rop, op)
end
function mod.z_out_raw(stream, op)
return bind.__gmpz_out_raw(stream, op)
end
function mod.z_out_str(stream, base, op)
return bind.__gmpz_out_str(stream, base, op)
end
function mod.z_perfect_power_p(op)
return bind.__gmpz_perfect_power_p(op)
end
function mod.z_perfect_square_p(op)
return bind.__gmpz_perfect_square_p(op)
end
function mod.z_popcount(op)
return bind.__gmpz_popcount(op)
end
function mod.z_pow_ui(rop, base, exp)
bind.__gmpz_pow_ui(rop, base, exp)
end
function mod.z_powm(rop, base, exp, mod)
bind.__gmpz_powm(rop, base, exp, mod)
end
function mod.z_powm_sec(rop, base, exp, mod)
bind.__gmpz_powm_sec(rop, base, exp, mod)
end
function mod.z_powm_ui(rop, base, exp, mod)
bind.__gmpz_powm_ui(rop, base, exp, mod)
end
function mod.z_probab_prime_p(n, reps)
return bind.__gmpz_probab_prime_p(n, reps)
end
function mod.z_random(rop, max_size)
bind.__gmpz_random(rop, max_size)
end
function mod.z_random2(rop, max_size)
bind.__gmpz_random2(rop, max_size)
end
function mod.z_realloc2(x, n)
bind.__gmpz_realloc2(x, n)
end
function mod.z_remove(rop, op, f)
return bind.__gmpz_remove(rop, op, f)
end
function mod.z_root(rop, op, n)
return bind.__gmpz_root(rop, op, n)
end
function mod.z_rootrem(root, rem, u, n)
bind.__gmpz_rootrem(root, rem, u, n)
end
function mod.z_rrandomb(rop, state, n)
bind.__gmpz_rrandomb(rop, state, n)
end
function mod.z_scan0(op, starting_bit)
return bind.__gmpz_scan0(op, starting_bit)
end
function mod.z_scan1(op, starting_bit)
return bind.__gmpz_scan1(op, starting_bit)
end
function mod.z_set(rop, op)
bind.__gmpz_set(rop, op)
end
function mod.z_set_d(rop, op)
bind.__gmpz_set_d(rop, op)
end
function mod.z_set_f(rop, op)
bind.__gmpz_set_f(rop, op)
end
function mod.z_set_q(rop, op)
bind.__gmpz_set_q(rop, op)
end
function mod.z_set_si(rop, op)
bind.__gmpz_set_si(rop, op)
end
function mod.z_set_str(rop, str, base)
return bind.__gmpz_set_str(rop, str, base)
end
function mod.z_set_ui(rop, op)
bind.__gmpz_set_ui(rop, op)
end
function mod.z_setbit(rop, bit_index)
bind.__gmpz_setbit(rop, bit_index)
end
function mod.z_size(op)
return bind.__gmpz_size(op)
end
function mod.z_sizeinbase(op, base)
return bind.__gmpz_sizeinbase(op, base)
end
function mod.z_sqrt(rop, op)
bind.__gmpz_sqrt(rop, op)
end
function mod.z_sqrtrem(rop1, rop2, op)
bind.__gmpz_sqrtrem(rop1, rop2, op)
end
function mod.z_sub(rop, op1, op2)
bind.__gmpz_sub(rop, op1, op2)
end
function mod.z_sub_ui(rop, op1, op2)
bind.__gmpz_sub_ui(rop, op1, op2)
end
function mod.z_ui_sub(rop, op1, op2)
bind.__gmpz_ui_sub(rop, op1, op2)
end
function mod.z_submul(rop, op1, op2)
bind.__gmpz_submul(rop, op1, op2)
end
function mod.z_submul_ui(rop, op1, op2)
bind.__gmpz_submul_ui(rop, op1, op2)
end
function mod.z_swap(rop1, rop2)
bind.__gmpz_swap(rop1, rop2)
end