Thread: HUGE custom data type

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    United States
    Posts
    6

    HUGE custom data type

    Is it possible to define a custom data type? Say, one that holds approximately... 10 million digits?!!

    Just curious. Is this possible? Otherwise, how can I work with insanely huge integers?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Consider GMP.
    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

  3. #3
    Registered User divineleft's Avatar
    Join Date
    Jul 2006
    Posts
    158
    i recommend gmp as well for large integers
    Gentoo Linux - 2.6.22.1
    GCC version 4.2.0

  4. #4
    Registered User
    Join Date
    Jun 2007
    Location
    Lees Summit Missouri
    Posts
    11

    What exactly would you like to do?

    Just for this post my integer literals are decimal.

    If you're trying to generate multiples or powers of low integers like 1,2,3,4,5,etc
    you might be able to pull it off by
    using an array.

    If however,you want something complex like square roots or large primes then I
    would suggest GMP. I never figured out how to use any other C libraries though.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I've written my own easy to use and understand, huge-number class.
    You can find it on the useful classes link from the page in my signature.

    However 10 million decimal digits is pretty extreme. They'd take a little over 30MB each! That would probably blow the stack in my code, even though I've done a fair bit to reduce stack usage.

    Determining if a large number is prime is extremely hard to do in a scalable manner, but things like square root aren't much trouble.

    Whether or not you need to use such a thing depends on exactly what you are wanting to do. There are a number of algorithms which output a large number of digits but don't involve storing the entire answer at every point through the calculation. Please explain your intent.
    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. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM