# Thread: how i can store 2^99999 in integer variable

1. ## how i can store 2^99999 in integer variable

can any one tell me how i can store

2^99999

in integer variable..........

2. The standard C integer types can't do it directly (They max out around 2^64, at best). You could use them to store the exponent, or something like that. The double type (I think) is capable of doing it - but it won't treat it as an integer and you're already getting close to the limits.

You might be interested in a library like GMP. You need to work through function calls instead of operators, but it allows you to work with integers with practically limitless precision. It's extremely fast considering what it does, and is portable. http://www.gmplib.org

3. Originally Posted by 62049913377
can any one tell me how i can store

2^99999

in integer variable..........
You need an integer with at least 99999 significant bits!

4. Depends on what you mean by an "integer variable", and what you plan to use it for.

5. Originally Posted by sean
The double type (I think) is capable of doing it - but it won't treat it as an integer and you're already getting close to the limits.
A value of that size cannot be stored in any practical (i.e. existing, native) floating point types, AFAIK. Even the IEEE-754 binary128 representation cannot hold a value of that size.

6. Originally Posted by grumpy
A value of that size cannot be stored in any practical (i.e. existing, native) floating point types, AFAIK. Even the IEEE-754 binary128 representation cannot hold a value of that size.
Yep! unless one creates a new type that has ninety nine thousand nine hundred ninety nine bits in it.

7. I agree with iMalc though: it depends on what you are trying to do with it. It may suffice to use a single bit to store the number (e.g., you are trying to represent a choice between 0 and 2^99999), or perhaps an int or long to store 99999 (e.g., you are working with powers of two only, so you just keep track of the exponent in order to store the number).

8. That, and if all you want to do is read in two long strings of digits and print the result of their addition (for example) then the ideal method is quite different to if you need to do all sorts of things such as multiplication, division, or square root on the large numbers etc.