biginteger.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // biginteger.h
  3. // bigdecimal
  4. //
  5. // Created by Sam Jaffe on 6/30/17.
  6. //
  7. #pragma once
  8. #include <string>
  9. #include <vector>
  10. namespace math {
  11. class biginteger {
  12. public:
  13. using data_type = std::vector<int32_t>;
  14. static constexpr int32_t const MAX_SEG { 999999999};
  15. static constexpr int32_t const OVER_SEG {1000000000};
  16. static constexpr int32_t const SEG_DIGITS{ 9};
  17. public:
  18. // Constructors
  19. biginteger();
  20. biginteger(int32_t);
  21. biginteger(uint32_t);
  22. biginteger(int64_t);
  23. biginteger(uint64_t);
  24. biginteger(char const *);
  25. // Unary operators
  26. biginteger operator-() const;
  27. // Binary operators
  28. friend biginteger operator+(biginteger const &, biginteger const &);
  29. friend biginteger operator-(biginteger const &, biginteger const &);
  30. friend biginteger operator*(biginteger const &, biginteger const &);
  31. friend biginteger operator/(biginteger const &, biginteger const &);
  32. friend biginteger & operator+=(biginteger &, biginteger const &);
  33. friend biginteger & operator-=(biginteger &, biginteger const &);
  34. friend biginteger & operator*=(biginteger &, biginteger const &);
  35. friend biginteger & operator/=(biginteger &, biginteger const &);
  36. // Output
  37. std::string to_string() const;
  38. // Comparison
  39. friend bool operator==(biginteger const &, biginteger const &);
  40. friend bool operator!=(biginteger const &, biginteger const &);
  41. friend bool operator<=(biginteger const &, biginteger const &);
  42. friend bool operator< (biginteger const &, biginteger const &);
  43. friend bool operator>=(biginteger const &, biginteger const &);
  44. friend bool operator> (biginteger const &, biginteger const &);
  45. private:
  46. biginteger(bool, uint64_t);
  47. biginteger(bool, data_type &&);
  48. friend void swap(biginteger & rhs, biginteger & lhs) {
  49. using std::swap;
  50. swap(rhs.is_negative, lhs.is_negative);
  51. swap(rhs.data, lhs.data);
  52. }
  53. bool is_negative;
  54. data_type data{};
  55. };
  56. }