|
-
Mar 15th, 2008, 12:06 AM
#1
Thread Starter
Fanatic Member
nth root
Does anyone have a code example of how to calculate the nth root of large numbers that have hundreds of digits?
-
Mar 15th, 2008, 05:49 PM
#2
Re: nth root
You could try numerical methods (like Newton's Method) to solve the polynomial xn = c--that is, xn - c = 0. Newton's Method is rudimentary but should produce an accurate result in about as many iterations as you want digits of accuracy. Code for this method should be easy to come by or write yourself if you decide to try it.
You could also perform a successive guess-and-check if speed isn't an issue. Guess zero and some arbitrary number (perhaps c/n), then guess midway between the two, pick only the half that could possibly be correct, and repeat as needed. You would end up performing a binary search for the number which would converge quite quickly.
Good luck finding a method!
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Mar 15th, 2008, 06:27 PM
#3
Thread Starter
Fanatic Member
Re: nth root
jemidiah,
Yeah, I'm already aware of the methods, but it's not as easy as you'd think because of the size of the numbers.
I've written some code to add, subtract, and multiply large integers, but I was hoping to refine some existing code for the nth root.
-
Mar 17th, 2008, 08:59 PM
#4
Re: nth root
I got to remembering that Python uses infinite-precision integers. Perhaps you could check python.org for the C(++) code that handles this and use whatever they used.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Mar 17th, 2008, 10:24 PM
#5
Thread Starter
Fanatic Member
Re: nth root
Oh now you tell me. Just kiding.
Thanks, I'll take a look although I've been working on my own too.
Either way I'll be posting it openly for everyone in need.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|