I am writing a combinations calculator and for the bigger calculations I end up hitting an overflow with long long int or int64_t. Is it possible to perhaps, at least, convert the number to something of this sort: 6.7090373691429E+19?
Here is my code:
#include <iostream>
#include <string.h>
#include <math.h>
int main() {
std::string charset;
int i, length; int64_t total = 0;
std::cout << "Charset: ";
std::cin >> charset;
std::cout << "Length: ";
std::cin >> length;
for (i=0;i<(length+1);i++) {
total += pow(charset.size(),i);
}
std::cout << "\nPossible combinations: " << total << std::endl;
return 0;
}
The C++ standard library does not include arbitrary size integer types.
You can use Boost Multiprecision for this. It has different backends, using dedicated libraries (e.g. GMP) and a custom backend without external dependencies (cpp_int).
Edit: To be fair, vsoftco already mentioned Boost Multiprecision in a comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With