1 module deimos.gmp.gmp; 2 3 enum GMP_LIMB_BITS = 64; 4 enum GMP_NAIL_BITS = 0; 5 6 enum GMP_NUMB_BITS = GMP_LIMB_BITS - GMP_NAIL_BITS; 7 enum GMP_NUMB_MASK = ((~ cast(mp_limb_t)(0)) >> GMP_NAIL_BITS); 8 enum GMP_NUMB_MAX = GMP_NUMB_MASK; 9 enum GMP_NAIL_MASK = ~ GMP_NUMB_MASK; 10 11 import core.stdc.stddef; 12 import core.stdc.limits; 13 import core.stdc.config : c_long, c_ulong; 14 15 extern (C) nothrow: 16 17 version (__GMP_SHORT_LIMB){ 18 alias mp_limb_t = uint; 19 alias mp_limb_signed_t = int; 20 } else { 21 alias mp_limb_t = c_ulong; 22 alias mp_limb_signed_t = c_long; 23 } 24 alias mp_bitcnt_t = c_ulong; 25 26 struct __mpz_struct { 27 int _mp_alloc; 28 int _mp_size; 29 mp_limb_t * _mp_d; 30 } 31 32 alias MP_INT = __mpz_struct; 33 alias mpz_t = __mpz_struct; 34 35 alias mp_ptr = mp_limb_t*; 36 alias mp_srcptr = const mp_limb_t*; 37 38 alias mp_size_t = c_long; 39 alias mp_exp_t = c_long; 40 41 struct __mpq_struct { 42 __mpz_struct _mp_num; 43 __mpz_struct _mp_den; 44 } 45 46 alias MP_RAT = __mpq_struct; 47 alias mpq_t = __mpq_struct; 48 49 struct __mpf_struct { 50 int _mp_prec; 51 int _mp_size; 52 mp_exp_t _mp_exp; 53 mp_limb_t *_mp_d; 54 } 55 56 alias mpf_t = __mpf_struct[1]; 57 58 enum gmp_randalg_t { 59 GMP_RAND_ALG_DEFAULT = 0, 60 GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT 61 } 62 63 struct __gmp_randstate_struct { 64 mpz_t _mp_seed; 65 gmp_randalg_t _mp_alg; 66 union _mp_algdata { 67 void * _mp_lc; 68 }; 69 } 70 71 alias gmp_randstate_t = __gmp_randstate_struct; 72 73 alias mpz_srcptr = const __mpz_struct*; 74 alias mpz_ptr = __mpz_struct*; 75 alias mpf_srcptr = const __mpf_struct*; 76 alias mpf_ptr = __mpf_struct*; 77 alias mpq_srcptr = const __mpq_struct*; 78 alias mpq_ptr = __mpq_struct*; 79 80 T __GMP_ABS(T)(T x){return x >= 0 ? x : -x;} 81 T __GMP_MAX(T)(T x, T y){return x > y ? x : y;} 82 83 mpz_t mpq_numref(mpq_t Q){return Q._mp_num;} 84 mpz_t mpq_denref(mpq_t Q){return Q._mp_den;} 85 86 alias mp_set_memory_functions = __gmp_set_memory_functions; 87 extern (C) void __gmp_set_memory_functions (void *function(size_t), 88 void *function(void *, size_t, size_t), 89 void function(void *, size_t)); 90 91 alias mp_get_memory_functions = __gmp_get_memory_functions; 92 extern (C) void __gmp_get_memory_functions (void*function(size_t)*, 93 void * function(void*, size_t, size_t)*, 94 void function(void *, size_t)*); 95 96 alias mp_bits_per_limb = __gmp_bits_per_limb; 97 extern (C) extern __gshared const int __gmp_bits_per_limb; 98 99 alias gmp_errno = __gmp_errno; 100 extern (C) extern __gshared int __gmp_errno; 101 102 alias gmp_version = __gmp_version; 103 extern (C) extern __gshared const char * __gmp_version; 104 105 106 /**************** Random number routines. ****************/ 107 108 alias gmp_randinit = __gmp_randinit; 109 extern (C) void __gmp_randinit(gmp_randstate_t, gmp_randalg_t, ...); 110 111 alias gmp_randinit_default = __gmp_randinit_default; 112 extern (C) void __gmp_randinit_default(gmp_randstate_t); 113 114 alias gmp_randinit_lc_2exp = __gmp_randinit_lc_2exp; 115 extern (C) void __gmp_randinit_lc_2exp(gmp_randstate_t, mpz_srcptr, c_ulong, mp_bitcnt_t); 116 117 alias gmp_randinit_lc_2exp_size = __gmp_randinit_lc_2exp_size; 118 extern (C) void __gmp_randinit_lc_2exp_size(gmp_randstate_t, mp_bitcnt_t); 119 120 alias gmp_randinit_mt = __gmp_randinit_mt; 121 extern (C) void __gmp_randinit_mt (gmp_randstate_t); 122 123 alias gmp_randinit_set = __gmp_randinit_set; 124 extern (C) void __gmp_randinit_set (gmp_randstate_t, const __gmp_randstate_struct *); 125 126 alias gmp_randseed = __gmp_randseed; 127 extern (C) void __gmp_randseed (gmp_randstate_t, mpz_srcptr); 128 129 alias gmp_randseed_ui = __gmp_randseed_ui; 130 extern (C) void __gmp_randseed_ui (gmp_randstate_t, c_ulong); 131 132 alias gmp_randclear = __gmp_randclear; 133 extern (C) void __gmp_randclear (gmp_randstate_t); 134 135 alias gmp_urandomb_ui = __gmp_urandomb_ui; 136 extern (C) c_ulong __gmp_urandomb_ui (gmp_randstate_t, c_ulong); 137 138 alias gmp_urandomm_ui = __gmp_urandomm_ui; 139 extern (C) c_ulong __gmp_urandomm_ui (gmp_randstate_t, c_ulong);