defining large datatypes

Discussion in 'C Programming' started by Nimo, Dec 29, 2010.

1. NimoGuest

hi.,

how to deal with numbers which has more than 20 digits..

as I can use a maximum of 'long long'; is there any way to handle
these type of values?

what data type I've to define? and is there any library available to
do these type of calclulations?

Thank You.
so long..

Nimo, Dec 29, 2010

2. David ResnickGuest

Google bignum or "arbitrary precision arithmetic", should get you
going. Could start here: http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic.
Yes, need a library. If you don't need precise answers, could use
doubles depending on your application and the range of values needed.

-David

David Resnick, Dec 29, 2010

3. AngusGuest

Or you could use a char array. But you would have to handle addition,
subtraction etc. But then you could support an unlimited number
size. The big int libraries will do all this for you in a very
efficient way.

Angus, Dec 31, 2010
4. BGBGuest

I have some library code to do arithmetic directly using ASCII strings
for input/output.

technically, it supports fairly large numbers (I forget the current max
size, and IIRC was something like 2048.2048 decimal digits or similar,

more often, smaller fixed-size numbers are more useful though, say,
using a fixed 128 bit number or such...

but, yeah, between using a bignum library or writing it themselves,
either is an option.

supporting variable-sized numbers is more generic, but is a little
harder to do as efficiently, since the logic has to be generic for
whatever input size it is passed (and even then, there needs to be some
practical limit to how big a number can be).

some claim "the number can be as big as there is memory to store it",
but often even such an implementation would be impractical (one needs
temporary memory to store intermediate results, or memory may be
fragmented, or say only 16 bits are used to store the number of machine
words in the result, or...).

and really, what is the liklihood of a person needing
multi-billion-digit numbers anyways?...

"the number may be absurdly huge" or "the number may be up to 629k
digits" or similar is plenty reasonable, without invoking the "numbers
as big as memory" claim.

or such...

BGB, Jan 3, 2011