Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic math operations with HUGE numbers

Tags:

c

math

bignum

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?

like image 283
mamidon Avatar asked Dec 04 '22 11:12

mamidon


2 Answers

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

like image 170
Rich K Avatar answered Dec 29 '22 08:12

Rich K


Same as any other number: Newton iteration.

like image 37
duffymo Avatar answered Dec 29 '22 08:12

duffymo