C++ class for dynamically sized signed integers larger than 64 bits
Works with any base up to and including UINT_MAX
Fully constexpr, except for friended I/O stream operators.
Compiles with C++23. gcc-13.2.0 with flags --std=c++23
used for testing
To use, include:
#include "big_int_all.hpp"
Almost all relevant operators are overloaded, e.g. operator+=
, operator/
, operator>=
, etc., as well as I/O stream operators.
Some simple math functions are provided: abs
, sqrt
, pow
, log
, gcd
, lcm
, factorial
.
Other member functions: size
, positive
, sign
, is_zero
, clone
, swap
, data
, bits
, digits
, digit_sum
, to_int
, str
, true_base
.
The below example prints the 100th Fibonacci number:
unsigned i = 0;
BigInt<1'000'000'000> F_p{ 0 }, F_n{ 1 }, temp;
do {
temp = F_n;
F_n += F_p;
F_p = temp;
++i;
} while(i != 100);
std::cout << F_n << std::endl; // 573147844013817084101
List
MAX_BASE
: equivalent toUINT_MAX
MAX_BINARY_BASE
: equivalent toUINT_MAX
MAX_DECIMAL_BASE
: equivalent to1'000'000'000
PRINT_BASE
: equivalent to1'000'000'000
DEFAULT_BASE
(default): equivalent to1'000'000'000
No support for unary.