Search code examples
cmathbignum

Basic math operations with HUGE numbers


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?


Solution

  • Same as any other number: Newton iteration.