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"
72 std::cerr <<
"\tFailed 1/6 (" << a <<
"!=400)" << std::endl;
75 std::cout <<
"\tPassed 1/6...";
79 std::cerr <<
"\tFailed 2/6 (" << a <<
"!=520)" << std::endl;
82 std::cout <<
"\tPassed 2/6...";
86 std::cerr <<
"\tFailed 3/6 (" << a <<
"!=5200)" << std::endl;
89 std::cout <<
"\tPassed 3/6...";
93 std::cerr <<
"\tFailed 4/6 (" << a <<
"!=5201)" << std::endl;
96 std::cout <<
"\tPassed 4/6...";
100 std::cerr <<
"\tFailed 5/6 (" << a <<
"!=5202)" << std::endl;
103 std::cout <<
"\tPassed 5/6...";
105 a = a +
large_number(
"7000000000000000000000000000000");
106 if (a !=
large_number(
"7000000000000000000000000005202")) {
107 std::cerr <<
"\tFailed 6/6 (" << a
108 <<
"!=7000000000000000000000000005202)" << std::endl;
111 std::cout <<
"\tPassed 6/6..." << std::endl;
120 std::cerr <<
"digit > 9!!\n";
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;
239 static_assert(std::is_integral<T>::value,
240 "Must be integer addition unsigned integer types.");
259 static_assert(std::is_integral<T>::value,
260 "Can only have integer types.");
265 uint64_t carry = 0, temp;
267 temp =
static_cast<uint64_t
>((*this)[i]) * n;
284 std::vector<unsigned char>
large_number(const large_number &a)
friend std::ostream & operator<<(std::ostream &out, const large_number &a)
large_number & operator++()
void add_digit(unsigned int value)
friend bool operator!=(large_number const &a, large_number const &b)
large_number(std::vector< unsigned char > &vec)
large_number & operator*=(const T n)
friend bool operator==(large_number const &a, large_number const &b)
unsigned char & operator[](size_t n)
large_number & operator++(int)
large_number & operator+=(large_number n)
large_number & operator=(const large_number &b)
friend large_number & operator+(const large_number &a, const T &b)
size_t num_digits() const
char digit_char(size_t i) const
std::vector< unsigned char > _digits