8#ifndef MATH_LARGE_NUMBER_H_
9#define MATH_LARGE_NUMBER_H_
55 for (
size_t i = strlen(number_str); i > 0; i--) {
56 char a = number_str[i - 1] -
'0';
66 std::cout <<
"------ Checking `large_number` class implementations\t"
105 a = a +
large_number(
"7000000000000000000000000000000");
106 if (a !=
large_number(
"7000000000000000000000000005202")) {
108 <<
"!=7000000000000000000000000005202)" <<
std::endl;
139 inline const unsigned char &
operator[](
size_t n)
const {
147 for (
size_t i = a.num_digits(); i > 0; i--)
148 out << static_cast<int>(a[i - 1]);
156 size_t N = a.num_digits();
159 for (
size_t i = 0; i < N; i++)
196 unsigned int carry = 0;
198 for (i = 0; i < max_L || carry != 0; i++) {
204 (*this)[i] = carry % 10;
240 "Must be integer addition unsigned integer types.");
260 "Can only have integer types.");
265 uint64_t carry = 0, temp;
267 temp =
static_cast<uint64_t
>((*this)[i]) * n;
Definition large_number.h:24
large_number(const large_number &a)
Definition large_number.h:48
large_number()
Definition large_number.h:27
friend std::ostream & operator<<(std::ostream &out, const large_number &a)
Definition large_number.h:146
void multiply(const T n)
Definition large_number.h:258
large_number & operator++()
Definition large_number.h:175
void add_digit(unsigned int value)
Definition large_number.h:118
friend bool operator!=(large_number const &a, large_number const &b)
Definition large_number.h:168
large_number(std::vector< unsigned char > &vec)
Definition large_number.h:51
large_number & operator*=(const T n)
Definition large_number.h:238
friend bool operator==(large_number const &a, large_number const &b)
Definition large_number.h:155
unsigned char & operator[](size_t n)
Definition large_number.h:137
large_number & operator++(int)
Definition large_number.h:183
static bool test()
Definition large_number.h:65
large_number & operator+=(large_number n)
Definition large_number.h:192
large_number & operator=(const large_number &b)
Definition large_number.h:229
friend large_number & operator+(const large_number &a, const T &b)
Definition large_number.h:220
size_t num_digits() const
Definition large_number.h:130
char digit_char(size_t i) const
Definition large_number.h:248
std::vector< unsigned char > _digits
Definition large_number.h:285
large_number(int n)
Definition large_number.h:39