FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Forum index » Science and Technology » Math » num-analysis
Java BigInteger
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
QCR
science forum beginner


Joined: 28 Jun 2006
Posts: 2

PostPosted: Wed Jun 28, 2006 1:25 pm    Post subject: Java BigInteger Reply with 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?

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];
Back to top
dave_and_darla@Juno.com
science forum beginner


Joined: 17 Oct 2005
Posts: 49

PostPosted: Wed Jun 28, 2006 2:38 pm    Post subject: Re: Java BigInteger Reply with quote

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
Back to top
QCR
science forum beginner


Joined: 28 Jun 2006
Posts: 2

PostPosted: Wed Jun 28, 2006 4:32 pm    Post subject: Re: Java BigInteger Reply with quote

Spot on; code below
thanks ...

import java.math.*;

public class logtest
{
public static void main(String[] args)
{
for (int i=1; i <=36; i++)
{
int data= (int)
(Math.ceil(1024 * (Math.log(i)/Math.log(2))));
System.out.println(i + ": " + data);
}
}
}
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sat Jan 10, 2009 3:26 am | All times are GMT
Forum index » Science and Technology » Math » num-analysis
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts recompiling Maxima with ABCL (Lisp im... robert.dodier@gmail.com Symbolic 3 Wed Jun 14, 2006 6:02 am
No new posts Virtual Globe 3D in Java: locating po... humberto.bortolossi@gmail Math 0 Sat Jun 03, 2006 2:39 am
No new posts Good linear programming in Java gooy Math 2 Tue Apr 18, 2006 12:30 pm
No new posts java ai project ravichoudhari Prediction 0 Sat Apr 01, 2006 6:00 am
No new posts java ai project ravichoudhari Recreational 1 Sat Apr 01, 2006 5:59 am

Internet Advertising | Western Union Locations | Bad Credit Mortgages | Credit Card | Apartment Budapest
Copyright © 2004-2005 DeniX Solutions SRL
Other DeniX Solutions sites: Electronics forum |  Medicine forum |  Unix/Linux blog |  Unix/Linux documentation |  Unix/Linux forums


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1809s ][ Queries: 16 (0.1127s) ][ GZIP on - Debug on ]