@@ -46,6 +46,7 @@ mutable struct BigInt <: Integer
4646 alloc:: Cint
4747 size:: Cint
4848 d:: Ptr{Limb}
49+
4950 function BigInt ()
5051 b = new (zero (Cint), zero (Cint), C_NULL )
5152 MPZ. init! (b)
@@ -77,9 +78,10 @@ BigInt(x)
7778function __init__ ()
7879 try
7980 if gmp_version (). major != GMP_VERSION. major || gmp_bits_per_limb () != GMP_BITS_PER_LIMB
80- error (string (" The dynamically loaded GMP library (version $(gmp_version ()) with __gmp_bits_per_limb == $(gmp_bits_per_limb ()) )\n " ,
81- " does not correspond to the compile time version (version $GMP_VERSION with __gmp_bits_per_limb == $GMP_BITS_PER_LIMB ).\n " ,
82- " Please rebuild Julia." ))
81+ msg = gmp_bits_per_limb () != GMP_BITS_PER_LIMB ? error : warn
82+ msg (string (" The dynamically loaded GMP library (version $(gmp_version ()) with __gmp_bits_per_limb == $(gmp_bits_per_limb ()) )\n " ,
83+ " does not correspond to the compile time version (version $GMP_VERSION with __gmp_bits_per_limb == $GMP_BITS_PER_LIMB ).\n " ,
84+ " Please rebuild Julia." ))
8385 end
8486
8587 ccall ((:__gmp_set_memory_functions , :libgmp ), Void,
@@ -114,6 +116,9 @@ gmpz(op::Symbol) = (Symbol(:__gmpz_, op), :libgmp)
114116init! (x:: BigInt ) = (ccall ((:__gmpz_init , :libgmp ), Void, (mpz_t,), & x); x)
115117init2! (x:: BigInt , a) = (ccall ((:__gmpz_init2 , :libgmp ), Void, (mpz_t, bitcnt_t), & x, a); x)
116118
119+ realloc2! (x, a) = (ccall ((:__gmpz_realloc2 , :libgmp ), Void, (mpz_t, bitcnt_t), & x, a); x)
120+ realloc2 (a) = realloc2! (BigInt (), a)
121+
117122sizeinbase (a:: BigInt , b) = Int (ccall ((:__gmpz_sizeinbase , :libgmp ), Csize_t, (mpz_t, Cint), & a, b))
118123
119124for op in (:add , :sub , :mul , :fdiv_q , :tdiv_q , :fdiv_r , :tdiv_r , :gcd , :lcm , :and , :ior , :xor )
@@ -196,6 +201,9 @@ cmp_si(a::BigInt, b) = ccall((:__gmpz_cmp_si, :libgmp), Cint, (mpz_t, Clong), &a
196201cmp_ui (a:: BigInt , b) = ccall ((:__gmpz_cmp_ui , :libgmp ), Cint, (mpz_t, Culong), & a, b) % Int
197202cmp_d (a:: BigInt , b) = ccall ((:__gmpz_cmp_d , :libgmp ), Cint, (mpz_t, Cdouble), & a, b) % Int
198203
204+ mpn_cmp (a:: Ptr{Limb} , b:: Ptr{Limb} , c) = ccall ((:__gmpn_cmp , :libgmp ), Cint, (Ptr{Limb}, Ptr{Limb}, Clong), a, b, c)
205+ mpn_cmp (a:: BigInt , b:: BigInt , c) = mpn_cmp (a. d, b. d, c)
206+
199207get_str! (x, a, b:: BigInt ) = (ccall ((:__gmpz_get_str ,:libgmp ), Ptr{Cchar}, (Ptr{Cchar}, Cint, mpz_t), x, a, & b); x)
200208set_str! (x:: BigInt , a, b) = ccall ((:__gmpz_set_str , :libgmp ), Cint, (mpz_t, Ptr{UInt8}, Cint), & x, a, b) % Int
201209get_d (a:: BigInt ) = ccall ((:__gmpz_get_d , :libgmp ), Cdouble, (mpz_t,), & a)
0 commit comments