vendredi 22 mai 2015

Exceeding C++'s largest integer datatype

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;
}

Aucun commentaire:

Enregistrer un commentaire