added base operations

This commit is contained in:
Andrei Yankovich 2019-07-09 12:47:39 +03:00
parent 4742dcae6f
commit 3d3e0ebda4
2 changed files with 225 additions and 48 deletions

View File

@ -269,34 +269,7 @@ BigInt &BigInt::operator++() {
return *this;
}
bool operator!(const BigInt &val) {
return val == 0;
}
bool operator == (const BigInt& left, const BigInt& right) {
return mpz_cmp(left.data, right.data) == 0;
}
bool operator != (const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) != 0;
}
bool operator < ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) < 0;
}
bool operator > ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) > 0;
}
bool operator <= ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) <= 0;
}
bool operator >= ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) >= 0;
}
// move operators
BigInt operator >>(BigInt left, unsigned int right) {
mpn_rshift(left.data->_mp_d,
@ -362,3 +335,173 @@ BigInt& operator <<=(BigInt &left, int right) {
return left >>= right;
}
// other bin operators
BigInt operator ~(BigInt left) {
mpz_com(left.data, left.data);
return left;
}
BigInt operator |(BigInt left, const BigInt &right) {
mpz_ior(left.data, left.data, right.data);
return left;
}
BigInt operator |(const BigInt &left, int right) {
return left | BigInt(right);
}
BigInt operator |(const BigInt &left, unsigned int right) {
return left | BigInt(right);
}
BigInt& operator |=(BigInt &left, const BigInt &right) {
mpz_ior(left.data, left.data, right.data);
return left;
}
BigInt& operator |=(BigInt &left, int right) {
return left |= BigInt(right);
}
BigInt& operator |=(BigInt &left, unsigned int right) {
return left |= BigInt(right);
}
BigInt operator &(BigInt left, const BigInt &right) {
mpz_and(left.data, left.data, right.data);
return left;
}
BigInt operator &(const BigInt &left, int right) {
return left & BigInt(right);
}
BigInt operator &(const BigInt &left, unsigned int right) {
return left & BigInt(right);
}
BigInt& operator &=(BigInt &left, const BigInt &right) {
mpz_and(left.data, left.data, right.data);
return left;
}
BigInt& operator &=(BigInt &left, int right) {
return left &= BigInt(right);
}
BigInt& operator &=(BigInt &left, unsigned int right) {
return left &= BigInt(right);
}
BigInt operator ^(BigInt left, const BigInt &right) {
mpz_xor(left.data, left.data, right.data);
return left;
}
BigInt operator ^(const BigInt &left, int right) {
return left ^ BigInt(right);
}
BigInt operator ^(const BigInt &left, unsigned int right) {
return left ^ BigInt(right);
}
BigInt& operator ^=(BigInt &left, const BigInt &right) {
mpz_xor(left.data, left.data, right.data);
return left;
}
BigInt& operator ^=(BigInt &left, int right) {
return left ^= BigInt(right);
}
BigInt& operator ^=(BigInt &left, unsigned int right) {
return left ^= BigInt(right);
}
// logic operators
bool operator!(const BigInt &val) {
return val == 0;
}
bool operator == (const BigInt& left, const BigInt& right) {
return mpz_cmp(left.data, right.data) == 0;
}
bool operator == (const BigInt& left, unsigned int right) {
return mpz_cmp_ui(left.data, right) == 0;
}
bool operator == (const BigInt& left, int right) {
return mpz_cmp_si(left.data, right) == 0;
}
bool operator != (const BigInt &left, const BigInt& right) {
return !(left == right);
}
bool operator != (const BigInt &left, unsigned int right) {
return !(left == right);
}
bool operator != (const BigInt &left, int right) {
return !(left == right);
}
bool operator < ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) < 0;
}
bool operator < ( const BigInt &left, unsigned int right) {
return mpz_cmp_ui(left.data, right) < 0;
}
bool operator < ( const BigInt &left, int right) {
return mpz_cmp_si(left.data, right) < 0;
}
bool operator > ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) > 0;
}
bool operator > ( const BigInt &left, unsigned int right) {
return mpz_cmp_ui(left.data, right) > 0;
}
bool operator > ( const BigInt &left, int right) {
return mpz_cmp_si(left.data, right) > 0;
}
bool operator <= ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) <= 0;
}
bool operator <= ( const BigInt &left, unsigned int right) {
return mpz_cmp_ui(left.data, right) <= 0;
}
bool operator <= ( const BigInt &left, int right) {
return mpz_cmp_si(left.data, right) <= 0;
}
bool operator >= ( const BigInt &left, const BigInt& right) {
return mpz_cmp(left.data, right.data) >= 0;
}
bool operator >= ( const BigInt &left, unsigned int right) {
return mpz_cmp_ui(left.data, right) >= 0;
}
bool operator >= ( const BigInt &left, int right) {
return mpz_cmp_si(left.data, right) >= 0;
}
// cast operations
BigInt::operator bool() const {
return *this != 0;
}

View File

@ -79,25 +79,6 @@ public:
friend BigInt& operator %= ( BigInt &left, const BigInt& right);
friend bool operator == ( const BigInt& left, const BigInt& right);
friend bool operator != ( const BigInt& left, const BigInt& right);
friend bool operator == ( const BigInt& left, int right);
friend bool operator != ( const BigInt& left, int right);
friend bool operator < ( const BigInt& left, const BigInt& right);
friend bool operator > ( const BigInt& left, const BigInt& right);
friend bool operator < ( const BigInt& left, int right);
friend bool operator > ( const BigInt& left, int right);
friend bool operator <= ( const BigInt& left, const BigInt& right);
friend bool operator >= ( const BigInt& left, const BigInt& right);
friend bool operator <= ( const BigInt& left, int right);
friend bool operator >= ( const BigInt& left, int right);
friend bool operator!(const BigInt& val);
friend BigInt operator << ( BigInt left, int right);
friend BigInt operator >> ( BigInt left, int right);
@ -110,10 +91,63 @@ public:
friend BigInt& operator <<= ( BigInt &left, unsigned int right);
friend BigInt& operator >>= ( BigInt &left, unsigned int right);
friend bool operator == ( const BigInt& left, const BigInt& right);
friend bool operator == ( const BigInt& left, unsigned int right);
friend bool operator == ( const BigInt& left, int right);
friend bool operator != ( const BigInt& left, const BigInt& right);
friend bool operator != ( const BigInt& left, unsigned int right);
friend bool operator != ( const BigInt& left, int right);
friend bool operator < ( const BigInt& left, const BigInt& right);
friend bool operator < ( const BigInt& left, unsigned int right);
friend bool operator < ( const BigInt& left, int right);
friend bool operator > ( const BigInt& left, const BigInt& right);
friend bool operator > ( const BigInt& left, unsigned int right);
friend bool operator > ( const BigInt& left, int right);
friend bool operator <= ( const BigInt& left, const BigInt& right);
friend bool operator <= ( const BigInt& left, unsigned int right);
friend bool operator <= ( const BigInt& left, int right);
friend bool operator >= ( const BigInt& left, const BigInt& right);
friend bool operator >= ( const BigInt& left, unsigned int right);
friend bool operator >= ( const BigInt& left, int right);
friend bool operator!(const BigInt& val);
BigInt& operator-- ();
BigInt& operator++ ();
friend BigInt& operator~ (BigInt& val);
friend BigInt operator~ (BigInt val);
friend BigInt operator| (BigInt left, const BigInt& right);
friend BigInt operator| (const BigInt &left, int right);
friend BigInt operator| (const BigInt &left, unsigned int right);
friend BigInt& operator|= (BigInt &left, const BigInt& right);
friend BigInt& operator|= (BigInt &left, int right);
friend BigInt& operator|= (BigInt &left, unsigned int right);
friend BigInt operator& (BigInt left, const BigInt& right);
friend BigInt operator& (const BigInt &left, int right);
friend BigInt operator& (const BigInt &left, unsigned int right);
friend BigInt& operator&= (BigInt &left, const BigInt& right);
friend BigInt& operator&= (BigInt &left, int right);
friend BigInt& operator&= (BigInt &left, unsigned int right);
friend BigInt operator^ (BigInt left, const BigInt& right);
friend BigInt operator^ (const BigInt &left, int right);
friend BigInt operator^ (const BigInt &left, unsigned int right);
friend BigInt& operator^= (BigInt &left, const BigInt& right);
friend BigInt& operator^= (BigInt &left, int right);
friend BigInt& operator^= (BigInt &left, unsigned int right);
operator bool() const;
};