first commit of support 64bit numbers on 32 os

This commit is contained in:
Andrei Yankovich 2019-07-25 13:13:09 +03:00
parent b3a165a5c5
commit 9ebb2e79f9
4 changed files with 204 additions and 201 deletions

@ -31,7 +31,7 @@ BigInt::BigInt(const std::string &str, int base):
mpz_set_str(data, str.c_str(), base);
}
BigInt::BigInt(long val):
BigInt::BigInt(intMpz val):
BigInt() {
mpz_set_si(data, val);
}
@ -58,7 +58,7 @@ BigInt BigInt::powm(BigInt val, const BigInt &pow, const BigInt &mod) {
return val.powm(pow, mod);
}
BigInt &BigInt::pow(unsigned long pow) {
BigInt &BigInt::pow(uIntMpz pow) {
mpz_pow_ui(data, data, pow);
return *this;
}
@ -119,23 +119,23 @@ BigInt &BigInt::operator =(const std::string &imput) {
return *this;
}
BigInt &BigInt::operator =(long val) {
BigInt &BigInt::operator =(intMpz val) {
mpz_set_si(data, val);
return *this;
}
// add operators
BigInt operator +(BigInt left, long right) {
BigInt operator +(BigInt left, intMpz right) {
if (right >= 0) {
mpz_add_ui(left.data, left.data, static_cast<unsigned long>(right));
mpz_add_ui(left.data, left.data, static_cast<uIntMpz>(right));
return left;
}
return left -= std::abs(right);
}
BigInt operator +(long left, BigInt right) {
BigInt operator +(intMpz left, BigInt right) {
return right += left;
}
@ -152,9 +152,9 @@ BigInt operator +(const std::string &left, const BigInt &right) {
return BigInt(left) + right;
}
BigInt& operator +=(BigInt &left, long right) {
BigInt& operator +=(BigInt &left, intMpz right) {
if (right >= 0) {
mpz_add_ui(left.data, left.data, static_cast<unsigned long>(right));
mpz_add_ui(left.data, left.data, static_cast<uIntMpz>(right));
return left;
}
return left -= std::abs(right);
@ -176,17 +176,17 @@ BigInt operator -(BigInt left, const BigInt &right) {
return left;
}
BigInt operator -(BigInt left, long right) {
BigInt operator -(BigInt left, intMpz right) {
if (right >= 0) {
mpz_sub_ui(left.data, left.data, static_cast<unsigned long>(right));
mpz_sub_ui(left.data, left.data, static_cast<uIntMpz>(right));
return left;
}
return left += std::abs(right);
}
BigInt operator -(long left, BigInt right) {
BigInt operator -(intMpz left, BigInt right) {
if (left >= 0) {
mpz_ui_sub(right.data, static_cast<unsigned long>(left), right.data);
mpz_ui_sub(right.data, static_cast<uIntMpz>(left), right.data);
return right;
}
return right += std::abs(left);
@ -214,9 +214,9 @@ BigInt& operator -=(BigInt &left, const std::string &right) {
return left -= BigInt(right);
}
BigInt& operator -=(BigInt &left, long right) {
BigInt& operator -=(BigInt &left, intMpz right) {
if (right >= 0) {
mpz_sub_ui(left.data, left.data, static_cast<unsigned long>(right));
mpz_sub_ui(left.data, left.data, static_cast<uIntMpz>(right));
return left;
}
return left += std::abs(right);
@ -229,8 +229,8 @@ BigInt operator /(BigInt left, const BigInt &right) {
return left;
}
BigInt operator /(BigInt left, long right) {
mpz_tdiv_q_ui(left.data, left.data, static_cast<unsigned long>(std::abs(right)));
BigInt operator /(BigInt left, intMpz right) {
mpz_tdiv_q_ui(left.data, left.data, static_cast<uIntMpz>(std::abs(right)));
if (right >= 0) {
return left;
@ -242,7 +242,7 @@ BigInt operator /(BigInt left, const std::string &right) {
return left /= BigInt(right);
}
BigInt operator /(long left, BigInt right) {
BigInt operator /(intMpz left, BigInt right) {
return BigInt(left) / right;
}
@ -259,8 +259,8 @@ BigInt& operator /=(BigInt &left, const std::string &right) {
return left /= BigInt(right);
}
BigInt& operator /=(BigInt &left, long right) {
mpz_tdiv_q_ui(left.data, left.data, static_cast<unsigned long>(std::abs(right)));
BigInt& operator /=(BigInt &left, intMpz right) {
mpz_tdiv_q_ui(left.data, left.data, static_cast<uIntMpz>(std::abs(right)));
if (right >= 0) {
return left;
@ -274,8 +274,8 @@ BigInt operator *(BigInt left, const BigInt &right) {
return left;
}
BigInt operator *(BigInt left, long right) {
mpz_mul_ui(left.data, left.data, static_cast<unsigned long>(std::abs(right)));
BigInt operator *(BigInt left, intMpz right) {
mpz_mul_ui(left.data, left.data, static_cast<uIntMpz>(std::abs(right)));
if (right >= 0) {
return left;
@ -283,7 +283,7 @@ BigInt operator *(BigInt left, long right) {
return -left;
}
BigInt operator *(long left, BigInt right) {
BigInt operator *(intMpz left, BigInt right) {
return right *= left;
}
@ -304,8 +304,8 @@ BigInt& operator *=(BigInt &left, const std::string &right) {
return left *= BigInt(right);
}
BigInt& operator *=(BigInt &left, long right) {
mpz_mul_ui(left.data, left.data, static_cast<unsigned long>(std::abs(right)));
BigInt& operator *=(BigInt &left, intMpz right) {
mpz_mul_ui(left.data, left.data, static_cast<uIntMpz>(std::abs(right)));
if (right >= 0) {
return left;
@ -319,12 +319,12 @@ BigInt operator %(BigInt left, const BigInt &right) {
return left;
}
BigInt operator %(BigInt left, long right) {
mpz_tdiv_r_ui(left.data, left.data, static_cast<unsigned long>(std::abs(right)));
BigInt operator %(BigInt left, intMpz right) {
mpz_tdiv_r_ui(left.data, left.data, static_cast<uIntMpz>(std::abs(right)));
return left;
}
BigInt operator %(long left, BigInt right) {
BigInt operator %(intMpz left, BigInt right) {
return BigInt(left) % right;
}
@ -341,8 +341,8 @@ BigInt& operator %=(BigInt& left, const BigInt &right) {
return left;
}
BigInt& operator %=(BigInt& left, long right) {
mpz_tdiv_r_ui(left.data, left.data, static_cast<unsigned long>(std::abs(right)));
BigInt& operator %=(BigInt& left, intMpz right) {
mpz_tdiv_r_ui(left.data, left.data, static_cast<uIntMpz>(std::abs(right)));
return left;
}
@ -434,7 +434,7 @@ BigInt operator |(BigInt left, const BigInt &right) {
return left;
}
BigInt operator |(const BigInt &left, long right) {
BigInt operator |(const BigInt &left, intMpz right) {
return left | BigInt(right);
}
@ -443,7 +443,7 @@ BigInt& operator |=(BigInt &left, const BigInt &right) {
return left;
}
BigInt& operator |=(BigInt &left, long right) {
BigInt& operator |=(BigInt &left, intMpz right) {
return left |= BigInt(right);
}
@ -452,7 +452,7 @@ BigInt operator &(BigInt left, const BigInt &right) {
return left;
}
BigInt operator &(const BigInt &left, long right) {
BigInt operator &(const BigInt &left, intMpz right) {
return left & BigInt(right);
}
@ -462,7 +462,7 @@ BigInt& operator &=(BigInt &left, const BigInt &right) {
return left;
}
BigInt& operator &=(BigInt &left, long right) {
BigInt& operator &=(BigInt &left, intMpz right) {
return left &= BigInt(right);
}
@ -471,7 +471,7 @@ BigInt operator ^(BigInt left, const BigInt &right) {
return left;
}
BigInt operator ^(const BigInt &left, long right) {
BigInt operator ^(const BigInt &left, intMpz right) {
return left ^ BigInt(right);
}
@ -480,7 +480,7 @@ BigInt& operator ^=(BigInt &left, const BigInt &right) {
return left;
}
BigInt& operator ^=(BigInt &left, long right) {
BigInt& operator ^=(BigInt &left, intMpz right) {
return left ^= BigInt(right);
}
@ -495,7 +495,7 @@ bool operator == (const BigInt& left, const BigInt& right) {
return mpz_cmp(left.data, right.data) == 0;
}
bool operator == (const BigInt& left, long right) {
bool operator == (const BigInt& left, intMpz right) {
return mpz_cmp_si(left.data, right) == 0;
}
@ -503,7 +503,7 @@ bool operator == (const BigInt &left, const std::string &right) {
return left == BigInt(right);
}
bool operator == ( long left, const BigInt & right) {
bool operator == ( intMpz left, const BigInt & right) {
return right == left;
}
@ -515,7 +515,7 @@ bool operator != (const BigInt &left, const BigInt& right) {
return !(left == right);
}
bool operator != (const BigInt &left, long right) {
bool operator != (const BigInt &left, intMpz right) {
return !(left == right);
}
@ -523,7 +523,7 @@ bool operator != (const BigInt &left, const std::string &right) {
return left != BigInt(right);
}
bool operator != ( long left, const BigInt & right) {
bool operator != ( intMpz left, const BigInt & right) {
return right != left;
}
@ -535,7 +535,7 @@ bool operator < ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) < 0;
}
bool operator < ( const BigInt &left, long right) {
bool operator < ( const BigInt &left, intMpz right) {
return mpz_cmp_si(left.data, right) < 0;
}
@ -543,7 +543,7 @@ bool operator < ( const BigInt &left, const std::string &right) {
return left < BigInt(right);
}
bool operator < ( long left, const BigInt & right) {
bool operator < ( intMpz left, const BigInt & right) {
return right > left;
}
@ -555,7 +555,7 @@ bool operator > ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) > 0;
}
bool operator > ( const BigInt &left, long right) {
bool operator > ( const BigInt &left, intMpz right) {
return mpz_cmp_si(left.data, right) > 0;
}
@ -563,7 +563,7 @@ bool operator > ( const BigInt &left, const std::string &right) {
return left > BigInt(right);
}
bool operator > ( long left, const BigInt & right) {
bool operator > ( intMpz left, const BigInt & right) {
return right < left;
}
@ -575,7 +575,7 @@ bool operator <= ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) <= 0;
}
bool operator <= ( const BigInt &left, long right) {
bool operator <= ( const BigInt &left, intMpz right) {
return mpz_cmp_si(left.data, right) <= 0;
}
@ -583,7 +583,7 @@ bool operator <= ( const BigInt &left, const std::string &right) {
return left <= BigInt(right);
}
bool operator <= ( long left, const BigInt & right) {
bool operator <= ( intMpz left, const BigInt & right) {
return right >= left;
}
@ -595,7 +595,7 @@ bool operator >= ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) >= 0;
}
bool operator >= ( const BigInt &left, long right) {
bool operator >= ( const BigInt &left, intMpz right) {
return mpz_cmp_si(left.data, right) >= 0;
}
@ -603,7 +603,7 @@ bool operator >= ( const BigInt &left, const std::string &right) {
return left >= BigInt(right);
}
bool operator >= ( long left, const BigInt & right) {
bool operator >= ( intMpz left, const BigInt & right) {
return right <= left;
}

@ -24,7 +24,7 @@ public:
BigInt();
BigInt(const BigInt& val, int bitCount = -1);
BigInt(const std::string &imput, int base = 10);
BigInt(long val);
BigInt(intMpz val);
BigInt(char item, unsigned int size, int base);
std::string getString(int base = 10) const;
@ -33,7 +33,7 @@ public:
BigInt& powm(const BigInt &pow, const BigInt &mod);
static BigInt powm(BigInt val, const BigInt & pow, const BigInt &mod);
BigInt& pow(unsigned long pow);
BigInt& pow(uIntMpz pow);
BigInt& log(int base);
/**
* @brief sizeBits
@ -44,7 +44,7 @@ public:
/**
* @brief longBits
* @return current long in Bits of number
* @return current length in Bits of number
*/
int longBits() const;
int longBytes() const;
@ -65,61 +65,61 @@ public:
BigInt& operator = (const BigInt& val);
BigInt& operator = (const std::string &imput);
BigInt& operator = (long val);
BigInt& operator = (intMpz val);
friend BigInt operator + ( BigInt left, const BigInt& right);
friend BigInt operator + ( BigInt left, const std::string &right);
friend BigInt operator + ( BigInt left, long right);
friend BigInt operator + ( BigInt left, intMpz right);
friend BigInt operator + ( long left, BigInt right);
friend BigInt operator + ( intMpz left, BigInt right);
friend BigInt operator + ( const std::string &left, const BigInt &right);
friend BigInt& operator += ( BigInt &left, long right);
friend BigInt& operator += ( BigInt &left, intMpz right);
friend BigInt& operator += ( BigInt &left, const BigInt& right);
friend BigInt& operator += ( BigInt &left, const std::string &right);
friend BigInt operator - ( BigInt left, const BigInt& right);
friend BigInt operator - ( BigInt left, long right);
friend BigInt operator - ( BigInt left, intMpz right);
friend BigInt operator - ( BigInt left, const std::string &right);
friend BigInt operator - ( long right, BigInt left);
friend BigInt operator - ( intMpz right, BigInt left);
friend BigInt operator - ( const std::string &right, const BigInt &left);
friend BigInt operator-(BigInt val);
friend BigInt& operator -= ( BigInt &left, long right);
friend BigInt& operator -= ( BigInt &left, intMpz right);
friend BigInt& operator -= ( BigInt &left, const BigInt& right);
friend BigInt& operator -= ( BigInt &left, const std::string &right);
friend BigInt operator / ( BigInt left, const BigInt& right);
friend BigInt operator / ( BigInt left, const std::string &right);
friend BigInt operator / ( BigInt left, long right);
friend BigInt operator / ( long left, BigInt right);
friend BigInt operator / ( BigInt left, intMpz right);
friend BigInt operator / ( intMpz left, BigInt right);
friend BigInt operator / ( const std::string &left, const BigInt &right);
friend BigInt& operator /= ( BigInt &left, long right);
friend BigInt& operator /= ( BigInt &left, intMpz right);
friend BigInt& operator /= ( BigInt &left, const std::string &right);
friend BigInt& operator /= ( BigInt &left, const BigInt& right);
friend BigInt operator * ( BigInt left, const BigInt& right);
friend BigInt operator * ( BigInt left, const std::string &right);
friend BigInt operator * ( BigInt left, long right);
friend BigInt operator * ( BigInt left, intMpz right);
friend BigInt operator * ( long left, BigInt right);
friend BigInt operator * ( intMpz left, BigInt right);
friend BigInt& operator *= ( BigInt &left, const BigInt& right);
friend BigInt& operator *= ( BigInt &left, long right);
friend BigInt& operator *= ( BigInt &left, intMpz right);
friend BigInt& operator *= ( BigInt &left, const std::string &right);
friend BigInt operator % ( BigInt left, const BigInt& right);
friend BigInt operator % ( BigInt left, const std::string &right);
friend BigInt operator % ( BigInt left, long right);
friend BigInt operator % ( BigInt left, intMpz right);
friend BigInt operator % ( long left, BigInt right);
friend BigInt operator % ( intMpz left, BigInt right);
friend BigInt operator % ( const std::string & left, const BigInt &right);
friend BigInt& operator %= ( BigInt &left, long right);
friend BigInt& operator %= ( BigInt &left, intMpz right);
friend BigInt& operator %= ( BigInt &left, const std::string &right);
friend BigInt& operator %= ( BigInt &left, const BigInt& right);
@ -131,46 +131,46 @@ public:
friend BigInt& operator >>= ( BigInt &left, int right);
friend bool operator == ( const BigInt& left, const BigInt& right);
friend bool operator == ( const BigInt& left, long right);
friend bool operator == ( const BigInt& left, intMpz right);
friend bool operator == ( const BigInt& left, const std::string& right);
friend bool operator == ( const std::string& left, const BigInt& right);
friend bool operator == ( const BigInt& left, const std::string& right);
friend bool operator == ( long left, const std::string& right);
friend bool operator == ( intMpz left, const std::string& right);
friend bool operator != ( const BigInt& left, const BigInt& right);
friend bool operator != ( const BigInt& left, long right);
friend bool operator != ( const BigInt& left, intMpz right);
friend bool operator != ( const BigInt& left, const std::string& str);
friend bool operator != ( const std::string& left, const BigInt& right);
friend bool operator != ( const BigInt& left, const std::string& right);
friend bool operator != ( long left, const std::string& right);
friend bool operator != ( intMpz left, const std::string& right);
friend bool operator < ( const BigInt& left, const BigInt& right);
friend bool operator < ( const BigInt& left, long right);
friend bool operator < ( const BigInt& left, intMpz right);
friend bool operator < ( const BigInt& left, const std::string& str);
friend bool operator < ( const std::string& left, const BigInt& right);
friend bool operator < ( const BigInt& left, const std::string& right);
friend bool operator < ( long left, const std::string& right);
friend bool operator < ( intMpz left, const std::string& right);
friend bool operator > ( const BigInt& left, const BigInt& right);
friend bool operator > ( const BigInt& left, long right);
friend bool operator > ( const BigInt& left, intMpz right);
friend bool operator > ( const BigInt& left, const std::string& str);
friend bool operator > ( const std::string& left, const BigInt& right);
friend bool operator > ( const BigInt& left, const std::string& right);
friend bool operator > ( long left, const std::string& right);
friend bool operator > ( intMpz left, const std::string& right);
friend bool operator <= ( const BigInt& left, const BigInt& right);
friend bool operator <= ( const BigInt& left, long right);
friend bool operator <= ( const BigInt& left, intMpz right);
friend bool operator <= ( const BigInt& left, const std::string& str);
friend bool operator <= ( const std::string& left, const BigInt& right);
friend bool operator <= ( const BigInt& left, const std::string& right);
friend bool operator <= ( long left, const std::string& right);
friend bool operator <= ( intMpz left, const std::string& right);
friend bool operator >= ( const BigInt& left, const BigInt& right);
friend bool operator >= ( const BigInt& left, long right);
friend bool operator >= ( const BigInt& left, intMpz right);
friend bool operator >= ( const BigInt& left, const std::string& str);
friend bool operator >= ( const std::string& left, const BigInt& right);
friend bool operator >= ( const BigInt& left, const std::string& right);
friend bool operator >= ( long left, const std::string& right);
friend bool operator >= ( intMpz left, const std::string& right);
friend bool operator!(const BigInt& val);
@ -184,22 +184,22 @@ public:
friend BigInt operator~ (BigInt val);
friend BigInt operator| (BigInt left, const BigInt& right);
friend BigInt operator| (const BigInt &left, long right);
friend BigInt operator| (const BigInt &left, intMpz right);
friend BigInt& operator|= (BigInt &left, const BigInt& right);
friend BigInt& operator|= (BigInt &left, long right);
friend BigInt& operator|= (BigInt &left, intMpz right);
friend BigInt operator& (BigInt left, const BigInt& right);
friend BigInt operator& (const BigInt &left, long right);
friend BigInt operator& (const BigInt &left, intMpz right);
friend BigInt& operator&= (BigInt &left, const BigInt& right);
friend BigInt& operator&= (BigInt &left, long right);
friend BigInt& operator&= (BigInt &left, intMpz right);
friend BigInt operator^ (BigInt left, const BigInt& right);
friend BigInt operator^ (const BigInt &left, long right);
friend BigInt operator^ (const BigInt &left, intMpz right);
friend BigInt& operator^= (BigInt &left, const BigInt& right);
friend BigInt& operator^= (BigInt &left, long right);
friend BigInt& operator^= (BigInt &left, intMpz right);
};

@ -60,8 +60,8 @@ see https://www.gnu.org/licenses/. */
#define GMP_HLIMB_BIT ((mp_limb_t) 1 << (GMP_LIMB_BITS / 2))
#define GMP_LLIMB_MASK (GMP_HLIMB_BIT - 1)
#define GMP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT)
#define GMP_ULONG_HIGHBIT ((unsigned long) 1 << (GMP_ULONG_BITS - 1))
#define GMP_ULONG_BITS (sizeof(uIntMpz) * CHAR_BIT)
#define GMP_ULONG_HIGHBIT ((uIntMpz) 1 << (GMP_ULONG_BITS - 1))
#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
#define GMP_NEG_CAST(T,x) (-((T)((x) + 1) - 1))
@ -1474,19 +1474,19 @@ mpz_realloc (mpz_t r, mp_size_t size)
/* MPZ assignment and basic conversions. */
void
mpz_set_si (mpz_t r, signed long int x)
mpz_set_si (mpz_t r, intMpz x)
{
if (x >= 0)
mpz_set_ui (r, x);
else /* (x < 0) */
{
r->_mp_size = -1;
MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (unsigned long int, x);
MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (uIntMpz, x);
}
}
void
mpz_set_ui (mpz_t r, unsigned long int x)
mpz_set_ui (mpz_t r, uIntMpz x)
{
if (x > 0)
{
@ -1515,14 +1515,14 @@ mpz_set (mpz_t r, const mpz_t x)
}
void
mpz_init_set_si (mpz_t r, signed long int x)
mpz_init_set_si (mpz_t r, intMpz x)
{
mpz_init (r);
mpz_set_si (r, x);
}
void
mpz_init_set_ui (mpz_t r, unsigned long int x)
mpz_init_set_ui (mpz_t r, uIntMpz x)
{
mpz_init (r);
mpz_set_ui (r, x);
@ -1556,7 +1556,7 @@ mpz_fits_ulong_p (const mpz_t u)
return (us == (us > 0));
}
long int
intMpz
mpz_get_si (const mpz_t u)
{
if (u->_mp_size < 0)
@ -1566,7 +1566,7 @@ mpz_get_si (const mpz_t u)
return (long) (mpz_get_ui (u) & ~GMP_LIMB_HIGHBIT);
}
unsigned long int
uIntMpz
mpz_get_ui (const mpz_t u)
{
return u->_mp_size == 0 ? 0 : u->_mp_d[0];
@ -1780,7 +1780,7 @@ mpz_sgn (const mpz_t u)
}
int
mpz_cmp_si (const mpz_t u, long v)
mpz_cmp_si (const mpz_t u, intMpz v)
{
mp_size_t usize = u->_mp_size;
@ -1795,7 +1795,7 @@ mpz_cmp_si (const mpz_t u, long v)
}
int
mpz_cmp_ui (const mpz_t u, unsigned long v)
mpz_cmp_ui (const mpz_t u, uIntMpz v)
{
mp_size_t usize = u->_mp_size;
@ -1822,7 +1822,7 @@ mpz_cmp (const mpz_t a, const mpz_t b)
}
int
mpz_cmpabs_ui (const mpz_t u, unsigned long v)
mpz_cmpabs_ui (const mpz_t u, uIntMpz v)
{
if (GMP_ABS (u->_mp_size) > 1)
return 1;
@ -1864,7 +1864,7 @@ mpz_swap (mpz_t u, mpz_t v)
/* Adds to the absolute value. Returns new size, but doesn't store it. */
static mp_size_t
mpz_abs_add_ui (mpz_t r, const mpz_t a, unsigned long b)
mpz_abs_add_ui (mpz_t r, const mpz_t a, uIntMpz b)
{
mp_size_t an;
mp_ptr rp;
@ -1889,7 +1889,7 @@ mpz_abs_add_ui (mpz_t r, const mpz_t a, unsigned long b)
/* Subtract from the absolute value. Returns new size, (or -1 on underflow),
but doesn't store it. */
static mp_size_t
mpz_abs_sub_ui (mpz_t r, const mpz_t a, unsigned long b)
mpz_abs_sub_ui (mpz_t r, const mpz_t a, uIntMpz b)
{
mp_size_t an = GMP_ABS (a->_mp_size);
mp_ptr rp;
@ -1913,7 +1913,7 @@ mpz_abs_sub_ui (mpz_t r, const mpz_t a, unsigned long b)
}
void
mpz_add_ui (mpz_t r, const mpz_t a, unsigned long b)
mpz_add_ui (mpz_t r, const mpz_t a, uIntMpz b)
{
if (a->_mp_size >= 0)
r->_mp_size = mpz_abs_add_ui (r, a, b);
@ -1922,7 +1922,7 @@ mpz_add_ui (mpz_t r, const mpz_t a, unsigned long b)
}
void
mpz_sub_ui (mpz_t r, const mpz_t a, unsigned long b)
mpz_sub_ui (mpz_t r, const mpz_t a, uIntMpz b)
{
if (a->_mp_size < 0)
r->_mp_size = -mpz_abs_add_ui (r, a, b);
@ -1931,7 +1931,7 @@ mpz_sub_ui (mpz_t r, const mpz_t a, unsigned long b)
}
void
mpz_ui_sub (mpz_t r, unsigned long a, const mpz_t b)
mpz_ui_sub (mpz_t r, uIntMpz a, const mpz_t b)
{
if (b->_mp_size < 0)
r->_mp_size = mpz_abs_add_ui (r, b, a);
@ -2015,19 +2015,19 @@ mpz_sub (mpz_t r, const mpz_t a, const mpz_t b)
/* MPZ multiplication */
void
mpz_mul_si (mpz_t r, const mpz_t u, long int v)
mpz_mul_si (mpz_t r, const mpz_t u, intMpz v)
{
if (v < 0)
{
mpz_mul_ui (r, u, GMP_NEG_CAST (unsigned long int, v));
mpz_mul_ui (r, u, GMP_NEG_CAST (uIntMpz, v));
mpz_neg (r, r);
}
else
mpz_mul_ui (r, u, (unsigned long int) v);
mpz_mul_ui (r, u, (uIntMpz) v);
}
void
mpz_mul_ui (mpz_t r, const mpz_t u, unsigned long int v)
mpz_mul_ui (mpz_t r, const mpz_t u, uIntMpz v)
{
mp_size_t un, us;
mp_ptr tp;
@ -2124,7 +2124,7 @@ mpz_mul_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t bits)
}
void
mpz_addmul_ui (mpz_t r, const mpz_t u, unsigned long int v)
mpz_addmul_ui (mpz_t r, const mpz_t u, uIntMpz v)
{
mpz_t t;
mpz_init (t);
@ -2134,7 +2134,7 @@ mpz_addmul_ui (mpz_t r, const mpz_t u, unsigned long int v)
}
void
mpz_submul_ui (mpz_t r, const mpz_t u, unsigned long int v)
mpz_submul_ui (mpz_t r, const mpz_t u, uIntMpz v)
{
mpz_t t;
mpz_init (t);
@ -2530,9 +2530,9 @@ mpz_congruent_p (const mpz_t a, const mpz_t b, const mpz_t m)
return res;
}
static unsigned long
static uIntMpz
mpz_div_qr_ui (mpz_t q, mpz_t r,
const mpz_t n, unsigned long d, enum mpz_div_round_mode mode)
const mpz_t n, uIntMpz d, enum mpz_div_round_mode mode)
{
mp_size_t ns, qn;
mp_ptr qp;
@ -2586,90 +2586,90 @@ mpz_div_qr_ui (mpz_t q, mpz_t r,
return rl;
}
unsigned long
mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (q, r, n, d, GMP_DIV_CEIL);
}
unsigned long
mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (q, r, n, d, GMP_DIV_FLOOR);
}
unsigned long
mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (q, r, n, d, GMP_DIV_TRUNC);
}
unsigned long
mpz_cdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)
uIntMpz
mpz_cdiv_q_ui (mpz_t q, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_CEIL);
}
unsigned long
mpz_fdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)
uIntMpz
mpz_fdiv_q_ui (mpz_t q, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_FLOOR);
}
unsigned long
mpz_tdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)
uIntMpz
mpz_tdiv_q_ui (mpz_t q, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC);
}
unsigned long
mpz_cdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_cdiv_r_ui (mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_CEIL);
}
unsigned long
mpz_fdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_fdiv_r_ui (mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR);
}
unsigned long
mpz_tdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_tdiv_r_ui (mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_TRUNC);
}
unsigned long
mpz_cdiv_ui (const mpz_t n, unsigned long d)
uIntMpz
mpz_cdiv_ui (const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_CEIL);
}
unsigned long
mpz_fdiv_ui (const mpz_t n, unsigned long d)
uIntMpz
mpz_fdiv_ui (const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_FLOOR);
}
unsigned long
mpz_tdiv_ui (const mpz_t n, unsigned long d)
uIntMpz
mpz_tdiv_ui (const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC);
}
unsigned long
mpz_mod_ui (mpz_t r, const mpz_t n, unsigned long d)
uIntMpz
mpz_mod_ui (mpz_t r, const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR);
}
void
mpz_divexact_ui (mpz_t q, const mpz_t n, unsigned long d)
mpz_divexact_ui (mpz_t q, const mpz_t n, uIntMpz d)
{
gmp_assert_nocarry (mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC));
}
int
mpz_divisible_ui_p (const mpz_t n, unsigned long d)
mpz_divisible_ui_p (const mpz_t n, uIntMpz d)
{
return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC) == 0;
}
@ -2719,8 +2719,8 @@ mpn_gcd_11 (mp_limb_t u, mp_limb_t v)
return u << shift;
}
unsigned long
mpz_gcd_ui (mpz_t g, const mpz_t u, unsigned long v)
uIntMpz
mpz_gcd_ui (mpz_t g, const mpz_t u, uIntMpz v)
{
mp_size_t un;
@ -2828,7 +2828,7 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v)
if (u->_mp_size == 0)
{
/* g = 0 u + sgn(v) v */
signed long sign = mpz_sgn (v);
intMpz sign = mpz_sgn (v);
mpz_abs (g, v);
if (s)
mpz_set_ui (s, 0);
@ -2840,7 +2840,7 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v)
if (v->_mp_size == 0)
{
/* g = sgn(u) u + 0 v */
signed long sign = mpz_sgn (u);
intMpz sign = mpz_sgn (u);
mpz_abs (g, u);
if (s)
mpz_set_si (s, sign);
@ -3022,7 +3022,7 @@ mpz_lcm (mpz_t r, const mpz_t u, const mpz_t v)
}
void
mpz_lcm_ui (mpz_t r, const mpz_t u, unsigned long v)
mpz_lcm_ui (mpz_t r, const mpz_t u, uIntMpz v)
{
if (v == 0 || u->_mp_size == 0)
{
@ -3072,9 +3072,9 @@ mpz_invert (mpz_t r, const mpz_t u, const mpz_t m)
/* Higher level operations (sqrt, pow and root) */
void
mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
mpz_pow_ui (mpz_t r, const mpz_t b, uIntMpz e)
{
unsigned long bit;
uIntMpz bit;
mpz_t tr;
mpz_init_set_ui (tr, 1);
@ -3093,7 +3093,7 @@ mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
}
void
mpz_ui_pow_ui (mpz_t r, unsigned long blimb, unsigned long e)
mpz_ui_pow_ui (mpz_t r, uIntMpz blimb, uIntMpz e)
{
mpz_t b;
mpz_pow_ui (r, mpz_roinit_n (b, &blimb, 1), e);
@ -3205,7 +3205,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)
}
void
mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)
mpz_powm_ui (mpz_t r, const mpz_t b, uIntMpz elimb, const mpz_t m)
{
mpz_t e;
mpz_powm (r, b, mpz_roinit_n (e, &elimb, 1), m);
@ -3213,7 +3213,7 @@ mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)
/* x=trunc(y^(1/z)), r=y-x^z */
void
mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, unsigned long z)
mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, uIntMpz z)
{
int sgn;
mpz_t t, u;
@ -3273,7 +3273,7 @@ mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, unsigned long z)
}
int
mpz_root (mpz_t x, const mpz_t y, unsigned long z)
mpz_root (mpz_t x, const mpz_t y, uIntMpz z)
{
int res;
mpz_t r;
@ -3344,7 +3344,7 @@ mpn_sqrtrem (mp_ptr sp, mp_ptr rp, mp_srcptr p, mp_size_t n)
/* Combinatorics */
void
mpz_fac_ui (mpz_t x, unsigned long n)
mpz_fac_ui (mpz_t x, uIntMpz n)
{
mpz_set_ui (x, n + (n == 0));
while (n > 2)
@ -3352,7 +3352,7 @@ mpz_fac_ui (mpz_t x, unsigned long n)
}
void
mpz_bin_uiui (mpz_t r, unsigned long n, unsigned long k)
mpz_bin_uiui (mpz_t r, uIntMpz n, uIntMpz k)
{
mpz_t t;
@ -3450,7 +3450,7 @@ mpz_probab_prime_p (const mpz_t n, int reps)
for (j = 0, is_prime = 1; is_prime & (j < reps); j++)
{
mpz_set_ui (y, (unsigned long) j*j+j+41);
mpz_set_ui (y, (uIntMpz) j*j+j+41);
if (mpz_cmp (y, nm1) >= 0)
{
/* Don't try any further bases. This "early" break does not affect

@ -46,16 +46,19 @@ extern "C" {
#endif
void mp_set_memory_functions (void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t));
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t));
void mp_get_memory_functions (void *(**) (size_t),
void *(**) (void *, size_t, size_t),
void (**) (void *, size_t));
void *(**) (void *, size_t, size_t),
void (**) (void *, size_t));
typedef unsigned long mp_limb_t;
typedef long mp_size_t;
typedef unsigned long mp_bitcnt_t;
typedef unsigned long uIntMpz;
typedef long intMpz;
typedef uIntMpz mp_limb_t;
typedef intMpz mp_size_t;
typedef uIntMpz mp_bitcnt_t;
typedef mp_limb_t *mp_ptr;
typedef const mp_limb_t *mp_srcptr;
@ -63,10 +66,10 @@ typedef const mp_limb_t *mp_srcptr;
typedef struct
{
int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the _mp_d field. */
to by the _mp_d field. */
int _mp_size; /* abs(_mp_size) is the number of limbs the
last field points to. If _mp_size is
negative this is a negative number. */
last field points to. If _mp_size is
negative this is a negative number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
@ -127,10 +130,10 @@ void mpz_clear (mpz_t);
#define mpz_even_p(z) (! mpz_odd_p (z))
int mpz_sgn (const mpz_t);
int mpz_cmp_si (const mpz_t, long);
int mpz_cmp_ui (const mpz_t, unsigned long);
int mpz_cmp_si (const mpz_t, intMpz);
int mpz_cmp_ui (const mpz_t, uIntMpz);
int mpz_cmp (const mpz_t, const mpz_t);
int mpz_cmpabs_ui (const mpz_t, unsigned long);
int mpz_cmpabs_ui (const mpz_t, uIntMpz);
int mpz_cmpabs (const mpz_t, const mpz_t);
int mpz_cmp_d (const mpz_t, double);
int mpz_cmpabs_d (const mpz_t, double);
@ -139,19 +142,19 @@ void mpz_abs (mpz_t, const mpz_t);
void mpz_neg (mpz_t, const mpz_t);
void mpz_swap (mpz_t, mpz_t);
void mpz_add_ui (mpz_t, const mpz_t, unsigned long);
void mpz_add_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_add (mpz_t, const mpz_t, const mpz_t);
void mpz_sub_ui (mpz_t, const mpz_t, unsigned long);
void mpz_ui_sub (mpz_t, unsigned long, const mpz_t);
void mpz_sub_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_ui_sub (mpz_t, uIntMpz, const mpz_t);
void mpz_sub (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_si (mpz_t, const mpz_t, long int);
void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int);
void mpz_mul_si (mpz_t, const mpz_t, intMpz);
void mpz_mul_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_mul (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_addmul_ui (mpz_t, const mpz_t, unsigned long int);
void mpz_addmul_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_addmul (mpz_t, const mpz_t, const mpz_t);
void mpz_submul_ui (mpz_t, const mpz_t, unsigned long int);
void mpz_submul_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_submul (mpz_t, const mpz_t, const mpz_t);
void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
@ -178,29 +181,29 @@ void mpz_divexact (mpz_t, const mpz_t, const mpz_t);
int mpz_divisible_p (const mpz_t, const mpz_t);
int mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t);
unsigned long mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_fdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_tdiv_ui (const mpz_t, unsigned long);
uIntMpz mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_cdiv_q_ui (mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_fdiv_q_ui (mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_tdiv_q_ui (mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_cdiv_r_ui (mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_fdiv_r_ui (mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_tdiv_r_ui (mpz_t, const mpz_t, uIntMpz);
uIntMpz mpz_cdiv_ui (const mpz_t, uIntMpz);
uIntMpz mpz_fdiv_ui (const mpz_t, uIntMpz);
uIntMpz mpz_tdiv_ui (const mpz_t, uIntMpz);
unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long);
uIntMpz mpz_mod_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long);
void mpz_divexact_ui (mpz_t, const mpz_t, uIntMpz);
int mpz_divisible_ui_p (const mpz_t, unsigned long);
int mpz_divisible_ui_p (const mpz_t, uIntMpz);
unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long);
uIntMpz mpz_gcd_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_gcd (mpz_t, const mpz_t, const mpz_t);
void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t);
void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long);
void mpz_lcm_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_lcm (mpz_t, const mpz_t, const mpz_t);
int mpz_invert (mpz_t, const mpz_t, const mpz_t);
@ -208,16 +211,16 @@ void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);
void mpz_sqrt (mpz_t, const mpz_t);
int mpz_perfect_square_p (const mpz_t);
void mpz_pow_ui (mpz_t, const mpz_t, unsigned long);
void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long);
void mpz_pow_ui (mpz_t, const mpz_t, uIntMpz);
void mpz_ui_pow_ui (mpz_t, uIntMpz, uIntMpz);
void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);
void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t);
void mpz_powm_ui (mpz_t, const mpz_t, uIntMpz, const mpz_t);
void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long);
int mpz_root (mpz_t, const mpz_t, unsigned long);
void mpz_rootrem (mpz_t, mpz_t, const mpz_t, uIntMpz);
int mpz_root (mpz_t, const mpz_t, uIntMpz);
void mpz_fac_ui (mpz_t, unsigned long);
void mpz_bin_uiui (mpz_t, unsigned long, unsigned long);
void mpz_fac_ui (mpz_t, uIntMpz);
void mpz_bin_uiui (mpz_t, uIntMpz, uIntMpz);
int mpz_probab_prime_p (const mpz_t, int);
@ -238,8 +241,8 @@ mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
int mpz_fits_slong_p (const mpz_t);
int mpz_fits_ulong_p (const mpz_t);
long int mpz_get_si (const mpz_t);
unsigned long int mpz_get_ui (const mpz_t);
intMpz mpz_get_si (const mpz_t);
uIntMpz mpz_get_ui (const mpz_t);
double mpz_get_d (const mpz_t);
size_t mpz_size (const mpz_t);
mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t);
@ -253,13 +256,13 @@ mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);
#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
void mpz_set_si (mpz_t, signed long int);
void mpz_set_ui (mpz_t, unsigned long int);
void mpz_set_si (mpz_t, intMpz);
void mpz_set_ui (mpz_t, uIntMpz);
void mpz_set (mpz_t, const mpz_t);
void mpz_set_d (mpz_t, double);
void mpz_init_set_si (mpz_t, signed long int);
void mpz_init_set_ui (mpz_t, unsigned long int);
void mpz_init_set_si (mpz_t, intMpz);
void mpz_init_set_ui (mpz_t, uIntMpz);
void mpz_init_set (mpz_t, const mpz_t);
void mpz_init_set_d (mpz_t, double);