QCR science forum beginner
Joined: 28 Jun 2006
Posts: 2
|
Posted: Wed Jun 28, 2006 1:25 pm Post subject:
Java BigInteger
|
|
|
Hmm - I found the following code snippets in java.math.BigInteger. The
code determines the array-size required for an arbitrary-precision
magnitude. In examining bitsPerDigit[], one sees obvious values for
radices which are a multiple of 2: [2]:1024, [4]:2048, [8]:3072,
etc. Also seen are (to me) not so obvious values: [5]:2378,
[6]:2648, [7]:2875, etc
Can someone share some insights into how these values were selected?
Thanks ...
// bitsPerDigit in the given radix times 1024
// Rounded up to avoid underallocation.
private static long bitsPerDigit[] = { 0, 0,
1024, 1624, 2048, 2378, 2648, 2875, 3072, 3247, 3402, 3543,
3672, 3790, 3899, 4001, 4096, 4186, 4271, 4350, 4426, 4498,
4567, 4633, 4696, 4756, 4814, 4870, 4923, 4975, 5025, 5074,
5120, 5166, 5210, 5253, 5295};
// Pre-allocate array of expected size. May be too large but
// can never be too small. Typically exact.
int numBits =
(int)(((numDigits * bitsPerDigit[radix]) >>> 10) + 1);
int numWords = (numBits + 31) /32;
mag = new int[numWords]; |
|
dave_and_darla@Juno.com science forum beginner
Joined: 17 Oct 2005
Posts: 49
|
Posted: Wed Jun 28, 2006 2:38 pm Post subject:
Re: Java BigInteger
|
|
|
QCR wrote:
| Quote: | Hmm - I found the following code snippets in java.math.BigInteger. The
code determines the array-size required for an arbitrary-precision
magnitude. In examining bitsPerDigit[], one sees obvious values for
radices which are a multiple of 2: [2]:1024, [4]:2048, [8]:3072,
etc. Also seen are (to me) not so obvious values: [5]:2378,
[6]:2648, [7]:2875, etc
Can someone share some insights into how these values were selected?
|
Looks like the values are ceiling( 1024 * log_2(base) )
Dave |
|