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 into some other arbitrarily large (or small) number.

Adding and subtracting is quite simple (one f / m / byte at a time):

out_byteN = a_byteN + b_byteN + overflowBit 

For each byte, in this way, I can add / subtract, since I am reading the number from the disk and do not run the risk of running out of RAM.

For multiplication / division, just do it in a loop.

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

+4
source share
4 answers

Same as any other number: Iteration of Newton .

+7
source

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

+8
source

There are several ways: Bisection, Newtons, Householder.

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

+1
source

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

+1
source

All Articles