| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- //
- // biginteger.h
- // bigdecimal
- //
- // Created by Sam Jaffe on 6/30/17.
- //
- #pragma once
- #include <string>
- #include <vector>
- namespace math {
- class biginteger {
- public:
- using data_type = std::vector<int32_t>;
- static biginteger const ZERO, ONE, NEGATIVE_ONE;
- static constexpr int32_t const MAX_SEG { 999999999};
- static constexpr int32_t const OVER_SEG {1000000000};
- static constexpr int32_t const SEG_DIGITS{ 9};
- public:
- // Constructors
- biginteger();
- biginteger(int32_t);
- biginteger(uint32_t);
- biginteger(int64_t);
- biginteger(uint64_t);
- biginteger(char const *);
- // Unary operators
- biginteger operator-() const;
- // Binary operators
- friend biginteger operator+(biginteger const &, biginteger const &);
- friend biginteger operator-(biginteger const &, biginteger const &);
- friend biginteger operator*(biginteger const &, biginteger const &);
- friend biginteger operator/(biginteger const &, biginteger const &);
- friend biginteger & operator+=(biginteger &, biginteger const &);
- friend biginteger & operator-=(biginteger &, biginteger const &);
- friend biginteger & operator*=(biginteger &, biginteger const &);
- friend biginteger & operator/=(biginteger &, biginteger const &);
- // Output
- std::string to_string() const;
- // Comparison
- friend bool operator==(biginteger const &, biginteger const &);
- friend bool operator!=(biginteger const &, biginteger const &);
- friend bool operator<=(biginteger const &, biginteger const &);
- friend bool operator< (biginteger const &, biginteger const &);
- friend bool operator>=(biginteger const &, biginteger const &);
- friend bool operator> (biginteger const &, biginteger const &);
- private:
- biginteger(bool, uint64_t);
- biginteger(bool, data_type &&);
- friend void swap(biginteger & rhs, biginteger & lhs) {
- using std::swap;
- swap(rhs.is_negative, lhs.is_negative);
- swap(rhs.data, lhs.data);
- }
- bool is_negative;
- data_type data{};
- };
- }
|