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

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    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. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by 62049913377 View Post
    can any one tell me how i can store

    2^99999

    in integer variable..........
    You need an integer with at least 99999 significant bits!
    Devoted my life to programming...

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Depends on what you mean by an "integer variable", and what you plan to use it for.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by sean View Post
    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.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by grumpy View Post
    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. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,166
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Realloc()
    By krazyxazn in forum C Programming
    Replies: 10
    Last Post: 01-27-2010, 10:05 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. which variable can store words?
    By Hunterofman in forum C++ Programming
    Replies: 8
    Last Post: 04-28-2008, 05:59 PM
  4. Howto assign an address to an integer variable
    By daYz in forum C Programming
    Replies: 18
    Last Post: 02-24-2008, 10:19 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM