tags:

views:

191

answers:

4

By huge numbers, I mean if you took a gigabyte (instead of 4/8 bytes etc.) and tried to add/subtract/multiply/divide it by some other arbitrarily large (or small) number.

Adding and subtracting are rather easy (one k/m/byte at a time):

out_byteN = a_byteN + b_byteN + overflowBit 

For every byte, thus I can add/subtract as I read the number from the disk and not risk running out of RAM.

For multiplying/dividing, simply do the above in a loop.

But what about taking the nth root of a HUGE number?

+7  A: 

Same as any other number: Newton iteration.

duffymo
So, nth root for huge x would be: root = guess-(x^n-num)/(2x)?
Lanissum
No, your denominator is incorrect. Should be nx^(n-1)
duffymo
+7  A: 

Are you asking for something like "The GNU Multiple Precision Arithmetic Library" (at http://gmplib.org/)?

Rich K
You mean the GNU crash-your-program-with-`abort()`-when-passed-huge-numbers Multiprecision Arithmetic Library?
R..
+1  A: 

There are multiple ways: Bisection, Newtons, Householder's method.

http://en.wikipedia.org/wiki/Root-finding_algorithm

drewk
A: 

You can use an Arbitrary-precision Arithmetic library. BigDigits is a good one.

Rook