What is the exact value of arbitrary accuracy?

This may be a very simple question for some, but I would like to know the arbitrary precision value that appears on the first line in the JavaDoc BigInteger :

Immutable integers of arbitrary precision.

+3
source share
2 answers

The term fixed precision means that only a certain number of significant digits are stored in the internal representation. This means that you cannot imagine every integer with a value greater than some threshold.

With arbitrary integers, integers can be as large as possible ("arbitrarily large"), and the library will hold all the digits to the least significant unit. (This is obviously limited by the amount of memory on your computer.)

+6
source

This means that BigInteger uses as much space as needed to store an integer value.

Take int as an example. It has a fixed number of bits. In this case, you can save values ​​between -2,147,483,648 and 2,147,483,647 (inclusive). Thus, it is a type with fixed precision, and not a type of arbitrary precision. It cannot store values ​​outside this range.

With BigInteger you do not have this problem, because as soon as the assigned bits are not enough to store the exact value, BigInteger will simply add some bits to process the value again.

Arbitrary is actually not entirely true, because there are limitations due to the fact that there is only a limited amount of available memory. This limit is not set by the BigInteger class, but by the environment (VM / hardware / OS).

+3
source

All Articles