Skip to content

Commit

Permalink
Merge pull request #2 from QuasarApp/32bitSupport
Browse files Browse the repository at this point in the history
Support of 64bit numbers on 32Bit OS
  • Loading branch information
EndrII authored Jul 25, 2019
2 parents b3a165a + 794f3ec commit eae35ea
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 209 deletions.
94 changes: 47 additions & 47 deletions src/bigint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -274,16 +274,16 @@ 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;
}
return -left;
}

BigInt operator *(long left, BigInt right) {
BigInt operator *(intMpz left, BigInt right) {
return right *= left;
}

Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -495,15 +495,15 @@ 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;
}

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;
}

Expand All @@ -515,15 +515,15 @@ 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);
}

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;
}

Expand All @@ -535,15 +535,15 @@ 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;
}

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;
}

Expand All @@ -555,15 +555,15 @@ 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;
}

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;
}

Expand All @@ -575,15 +575,15 @@ 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;
}

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;
}

Expand All @@ -595,15 +595,15 @@ 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;
}

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;
}

Expand Down
Loading

0 comments on commit eae35ea

Please sign in to comment.