#ifndef BETTERSTL_BIG_INTEGER_HPP #define BETTERSTL_BIG_INTEGER_HPP #include #include #include namespace bstl { class BigInteger { public: BigInteger(); BigInteger(int value); BigInteger(long long value); BigInteger(unsigned long long value); explicit BigInteger(const std::string& value); explicit BigInteger(const char* value); BigInteger(const BigInteger& other) = default; BigInteger& operator=(const BigInteger& other) = default; [[nodiscard]] bool isZero() const; [[nodiscard]] int sign() const; [[nodiscard]] std::string toString() const; bool operator==(const BigInteger& other) const; bool operator!=(const BigInteger& other) const; bool operator<(const BigInteger& other) const; bool operator>(const BigInteger& other) const; bool operator<=(const BigInteger& other) const; bool operator>=(const BigInteger& other) const; bool operator==(int value) const; bool operator!=(int value) const; bool operator<(int value) const; bool operator>(int value) const; bool operator<=(int value) const; bool operator>=(int value) const; bool operator==(long long value) const; bool operator!=(long long value) const; bool operator<(long long value) const; bool operator>(long long value) const; bool operator<=(long long value) const; bool operator>=(long long value) const; BigInteger operator+() const; BigInteger operator-() const; BigInteger& operator+=(const BigInteger& other); BigInteger& operator-=(const BigInteger& other); BigInteger& operator*=(const BigInteger& other); BigInteger& operator/=(const BigInteger& other); BigInteger operator+(const BigInteger& other) const; BigInteger operator-(const BigInteger& other) const; BigInteger operator*(const BigInteger& other) const; BigInteger operator/(const BigInteger& other) const; private: std::vector m_digits; // 无符号数字,低位在前 int m_sign; // -1, 0, 1 static std::vector m_trimLeadingZeros(const std::vector& value); static int m_compareAbs(const std::vector& a, const std::vector& b); static std::vector m_addAbs(const std::vector& a, const std::vector& b); static std::vector m_subAbs(const std::vector& a, const std::vector& b); static std::vector m_mulAbs(const std::vector& a, const std::vector& b); static std::vector m_divAbs(const std::vector& a, const std::vector& b); }; // 流运算符重载 std::ostream& operator<<(std::ostream& os, const BigInteger& bi); std::istream& operator>>(std::istream& is, BigInteger& bi); } // namespace bstl #endif //BETTERSTL_BIG_INTEGER_HPP