What does BigInteger mean without limitation?

I examined this question overflowing https://stackoverflow.com/a/2129441/ and, in particular, I do not understand this line (words in italics):

In the BigInteger class, I have no restrictions, and there are some useful functions there, but it is rather depressing to convert your beautiful code to work with the BigInteger class, especially when the primitive operators do not work there, and you should use the functions of this class.

I don’t know what I’m missing, but will you need endless memory to represent something that has no limit? What is this trick?

+39
java biginteger integer-overflow
Aug 23 '12 at 9:16
source share
4 answers

There is no theoretical limit. The BigInteger class allocates as much memory as needed for all data bits that you want to hold.

However, there are some practical limits dictated by available memory. There are other technical limitations, although you are unlikely to be affected: some methods assume that the bits are addressed by int indices, so breaks will start when you go to Integer.MAX_VALUE bits.

+65
Aug 23 '12 at 9:18
source share
Graham gave an excellent answer to this question. I would only add that you need to be careful with the valueOf , because it is created using the long parameter , so the maximum value is Long.MAX_VALUE .
+13
Aug 23 2018-12-12T00:
source share

Yes, it is used when we need very large numbers with arbitrary precision. It is important to note that “arbitrary” accuracy or the number of digits does not mean “unlimited”: this means that the number of digits in the number or number of precision digits in the calculation is limited by the memory and / or certain accuracy limits that we specify.

+3
Aug 23 2018-12-12T00:
source share

Look at the source code of the BigInteger class, you will see (this can be done using NetBean). The number will be represented as int arrays. For example, 10113 would be [1, 0, 1, 1, 3] (this is not exactly what the BigInteger class does, just an example of how a large module works). Thus, technically, the only limitation will be your memory.

+2
Nov 27 '16 at 16:30
source share



All Articles