Raising to power returns zero

I'm trying to find the maximum number of combinations for a given character set and string length using the formula charsetLength to the power of stringLength.

Simple, right?

My character set contains sixty-two characters, and when the string length is set to eleven characters or more, the power function returns zero.

Here's the code I'm using:

1
2
3
4
5
	unsigned long long keyspaceSize; // Number of possible combinations
	int charsetLength = 62; // Length of charset
	int maxChars = 12; // Length of string

	keyspaceSize = pow((long double)charsetLength, maxChars);


After running this, the value of keyspaceSize will be zero. (obviously it's not correct.) I can't figure out what's wrong here. When I try

cout << pow(62, 12);

Everything works fine, the result is printed in scientific notation.


Any idea how I can get the proper size here?

EDIT: I've just found that a 64-bit integer is too small to hold this number. Are there any cross platform high-speed methods of storing larger integers?
Last edited on
GMP.

You could also staple two long longs together and do the exponentiation yourself.

EDIT: Oh, and long long is neither cross-platform nor standard.
Last edited on
Topic archived. No new replies allowed.