Results 1 to 2 of 2
Thread: BigInteger nth root
 08292011, 06:33 AM #1Member
 Join Date
 Aug 2011
 Posts
 1
 Rep Power
 0
 08292011, 09:47 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
If you apply that naive Newton (Raphson) method you're using to many calculations per step; consider the following method:
Let xl and xh be such that xl**n <= x <= xh**n (** is the power operator)
A better estimation would be (xl+xh)>>1
Continue the above steps until you have found the nth root or xhxl <= 1
Calculating the nth power can be done as follows (the example uses simple ints)
Java Code:int pow(int x, int n) { if (n == 0) return 1; if (n == 1) return x; int r= pow(x, n>>1); int t= r; if ((n&1) == 1) r*= x; return t*r; }
JosLast edited by JosAH; 08292011 at 10:24 AM. Reason: typo ...
Build a wall around Donald Trump; I'll pay for it.
Similar Threads

BigInteger value of
By ccie007 in forum New To JavaReplies: 2Last Post: 09262010, 03:46 PM 
convert BigInteger
By bobo67 in forum New To JavaReplies: 1Last Post: 09012010, 02:00 PM 
BigInteger
By windows.login in forum New To JavaReplies: 8Last Post: 07132010, 01:10 PM 
very new... Biginteger problems
By willemien in forum New To JavaReplies: 6Last Post: 05022010, 03:17 PM 
how to convert from BigInteger to Hex
By nanaji in forum Advanced JavaReplies: 10Last Post: 05222008, 12:44 PM
Bookmarks