#include "BigInt.h" #include BigInt::~BigInt() { mpz_clear(m_Data); } BigInt::BigInt(BigInt&& a_Move) { std::swap(m_Data, a_Move.m_Data); } BigInt::BigInt(std::string&& a_Number) { mpz_init_set_str(m_Data, a_Number.c_str(), 10); } BigInt::BigInt(long a_Number) { mpz_init_set_si(m_Data, a_Number); } BigInt::BigInt(const BigInt& a_Copy) { mpz_init_set(m_Data, a_Copy.m_Data); } void BigInt::operator=(const BigInt& a_Other) { mpz_init_set(m_Data, a_Other.m_Data); } BigInt BigInt::operator+(const BigInt& a_Other) { BigInt result = *this; result += a_Other; return result; } BigInt BigInt::operator-(const BigInt& a_Other) { BigInt result = *this; result -= a_Other; return result; } BigInt BigInt::operator*(const BigInt& a_Other) { BigInt result = *this; result *= a_Other; return result; } BigInt BigInt::operator/(const BigInt& a_Other) { BigInt result = *this; result /= a_Other; return result; } BigInt BigInt::operator+=(const BigInt& a_Other) { mpz_add(m_Data, m_Data, a_Other.m_Data); return *this; } BigInt BigInt::operator-=(const BigInt& a_Other) { mpz_sub(m_Data, m_Data, a_Other.m_Data); return *this; } BigInt BigInt::operator*=(const BigInt& a_Other) { mpz_mul(m_Data, m_Data, a_Other.m_Data); return *this; } BigInt BigInt::operator/=(const BigInt& a_Other) { mpz_divexact(m_Data, m_Data, a_Other.m_Data); return *this; } bool BigInt::operator==(const BigInt& a_Other) { return mpz_cmp(m_Data, a_Other.m_Data) == 0; } const std::string BigInt::ToString() const { std::string result; result.reserve(mpz_sizeinbase(m_Data, 10) + 2); mpz_get_str(result.data(), 10, m_Data); return result.c_str(); } bool BigInt::IsEqualZero() const { return mpz_cmp_si(m_Data, 0) == 0; }