Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the precise meaning of arbitrary precision?

This might be a very simple question for some but I would like to know the meaning of arbitrary precision which appears in the first line in JavaDoc of BigInteger :

Immutable arbitrary-precision integers .

like image 977
Geek Avatar asked Aug 23 '12 09:08

Geek


1 Answers

It means that BigInteger uses as much space as is needed to save the whole value.

Take int as an example. It has a fixed amount of bits available. With that you can save values between -2,147,483,648 and 2,147,483,647 (inclusive). So it is a fixed-precision type and not an arbitrary-precision type. It can not store values outside of this range.

With BigInteger, you don't have that problem, because once the assigned bits are not enough to store the exact value, BigInteger will just add some bits so it can handle the value again.

Arbitrary is actually not really true, because there are limits due to the fact that there is only a finite amount of memory available. That limit is not given by the BigInteger class but by the environment (VM/hardware/OS).

like image 76
brimborium Avatar answered Sep 30 '22 10:09

brimborium