mamidon
mamidon

Reputation: 895

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?

Upvotes: 4

Views: 1957

Answers (4)

rook
rook

Reputation: 67019

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

Upvotes: 1

dawg
dawg

Reputation: 103824

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

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

Upvotes: 1

Rich K
Rich K

Reputation: 217

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

Upvotes: 8

duffymo
duffymo

Reputation: 308763

Same as any other number: Newton iteration.

Upvotes: 7

Related Questions