The question is pretty straightforward, does BigInteger have a limit? From what I know it is only limited to the amount of memory available on the system, nothing else. This question arose when my instructor told me that one could not calculate 50! using BigIntegers, which I believe one can. I would appreciate an answer.

Thank you.

I believe the true answer is irrelevant. Firstly it could differ based on implementation, and it is entirely possible that if it currently does have a limit, it would be removed in future. The big issue is that whether or not you have space for something is irrelevant.

There are certain numbers that are just so incredibly massive that they are assumed to be impossible to compute (http://en.wikipedia.org/wiki/Transcomputational_problem).

As it turns out 50! is not really all that big (relatively speaking) coming in at only 65 decimal digits. As such I would not be surprised if BigInteger COULD calculate it.

The thing is that if you start pushing the envelope of how big a number you can calculate you run into the wall of time and space. The algorithms will take time to run and there wont be enough space to run them. This is where the definition of a transcomputational problem comes in. A transcomputational problem is one which would take a computer the size of the earth longer than the age of the earth to compute. Obviously BigInteger frankly will be unable to deal with this, and even if it could it wouldn't matter since you could never get the output you need from it.

Luckily there are some clevel argorithms to keep big number use in check, often relying heavily on modular arithmetic (http://en.wikipedia.org/wiki/RSA_%28algorithm%29). If you really want to have fun with big numbers you will likely have to find a way to get time on a supercomputer (http://www.top500.org/list/2013/06/?page=1) and at that point BigInteger probably will be too slow for the task at hand.

In summary: if you really want to know how a particular class works, write it yourself.

The API shows the nuber of bits in a BigInteger to be both set and returned as an int, so the limit is 2^31 bits. That is part of the public API conrtract of the class, and is thus guaranteed. (It should also be within the memory size of a 2013 PC, if the VM memory size defaults are overidden).

Decimal 50 is less than 6 bits. 50! is certainly less than 50^50, which is less than 6*50 bits. Thus 50! is less than 300 bits - a trivial size for BigInteger.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.