Reputation: 11
Boost multiprecision libraries highest value possible
Can the boost multiprecision handle values as large as googolplex , like maybe the boost multiprecision cpp dec float library?
So can someone please tell me the largest value possible in any boost multiprecision library?
Upvotes: 1
Views: 47
Reputation: 393674
cpp_dec_float
would have been your best bet, solely because the base-10 mantissa is always 1 for googol(plex). However, the exponent type is required to be a builtin integer type. std::int128_t doesn't even qualify if the compiler supports it. So, that's right off.
Using GMP backends appears to break down at 5e+17 digits:
#include <boost/multiprecision/gmp.hpp>
#include <iostream>
int main() {
using namespace boost::multiprecision;
using Real = mpf_float;
using Int = mpz_int;
// create a googolplex
Int googol = pow(Int(10), 100u);
// print it
std::cout << googol << std::endl;
std::cout << "check: " << log10(Real(googol)) << std::endl;
// no plex for you
auto not_googolplex = pow(Real(10), Real("5e17"));
std::cout << "check: " << log10(not_googolplex) << std::endl;
not_googolplex = pow(Real(10), Real("5e18"));
std::cout << "check: " << log10(not_googolplex) << std::endl;
}
Printing (on my AMD64 64GiB box using GCC14 or Clang18 and Boost 1.86):
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
check: 100
check: 5e+17
GNU MP: Cannot allocate memory (size=4611686018427387960)
Aborted (core dumped)
Upvotes: 0