What is the precise meaning of arbitrary precision?
Asked Answered
G

2

12

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 .

Gynaecocracy answered 23/8, 2012 at 9:41 Comment(3)
How does this differ from your other question 15 minutes ago?Iolanthe
@Iolanthe I didn't know the meaning of arbitray precision while asking that question . Hence this question. If it turns out to be same one or the other can closed .Gynaecocracy
@Iolanthe I think they are different questions because this one is based on terminology, the other one is based on a technical statement that he didn't understand. They have the same answer though.Hedvige
T
9

The term fixed precision means that there are only a certain number of significant digits retained in the internal representation. This means that you would not be able to represent every integer with a magnitude greater than some threshold.

With arbitrary precision integers, the integers can be as large as you need ("arbitrarily large") and the library will keep all the digits down to the least significant unit. (This is obviously limited by the amount of memory in your computer.)

Tropical answered 23/8, 2012 at 9:45 Comment(0)
H
12

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).

Hedvige answered 23/8, 2012 at 9:47 Comment(0)
T
9

The term fixed precision means that there are only a certain number of significant digits retained in the internal representation. This means that you would not be able to represent every integer with a magnitude greater than some threshold.

With arbitrary precision integers, the integers can be as large as you need ("arbitrarily large") and the library will keep all the digits down to the least significant unit. (This is obviously limited by the amount of memory in your computer.)

Tropical answered 23/8, 2012 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.