defining large datatypes

N

Nimo

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..
 
D

David Resnick

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..

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
 
A

Angus

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

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.
 
B

BGB

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.

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,
but it is adjustable anyways...).

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top