Thread: Help needed with VERY large numbers.

  1. #1
    Registered User
    Join Date
    Jan 2004

    Help needed with VERY large numbers.

    I am trying to write a program that does integer math on extremely large numbers.

    Basically, I'm going to be multiplying two numbers in the range of 250 (decimal) digits together, and comparing the results to a much larger number (say 500 decimal digits). Based on the results of the comparison, one of the two initial numbers will be modified.

    My question is, how would I set these extremely long numbers as variables? I know that a 1560bit number will not fit into a "long long". Anyone know of any libraries or anything that might help me with this?


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001

    This was discussed recently...

    So, search the board. (I didn't follow the discussion, so I don't know the details.)

    There are libraries. You'd have to search the net.

    You could write your own, if you want to do it as a learning exercise... imagine that you are using one of those mechanical counters to count the number of people entering a stadium. If the counter only goes up to 999, what do you do? Get two of them and use the second one to count how many times the first one rolls-over. (Your mathmatical operations require a bit more thinking.)

    I see Salem beat me to it... with a better, more specific answer! ... I was afraid you were going to get a rude "Search the freekin' board" answer.

    BTW - I would not attempt to write my own BigInt library, unless I really wanted to. It could turn-out to be a bigger project, than the program that utilizes the library! It's almost always better to use a pre-existing library. (Of course, sometimes cost is a consideration too.)
    Last edited by DougDbug; 01-15-2004 at 06:34 PM.

  4. #4
    Registered User
    Join Date
    Jan 2004

    Does anyone know of any tutorials for using GMP? I am by far not a programmer, and I'm just trying to do some simple multiplication and compare the results. The GMP manual is great at telling how it does what it does, but for someone who struggles with basic "printf" commands, and needs to refer to a programming book to know how to do a carriage return line feed, they do not seem to offer much in the way of examples on how to use the library.

    Any help would be, well, helpful.

    Thank you for your time, and I apologize if this has already been covered on the forum, I tried searching the board for information on this, as well as, and I found a lot about GMP, but it was all too advanced for me.

    Thanks again!


  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    If you're that new to programming, I would suggest postponing this project until you are a good deal more familiar with the language, and programming in general. Perhaps make a smaller version of your program (with numbers computable by primitive types) now, and then move on later once you are familiar with OOP and using libraries, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Large numbers
    By password in forum C++ Programming
    Replies: 9
    Last Post: 06-28-2007, 02:15 AM
  2. Binary division of large numbers
    By hooper in forum C Programming
    Replies: 5
    Last Post: 06-01-2007, 02:33 AM
  3. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  4. How to return/use VERY LARGE numbers?
    By 99atlantic in forum C++ Programming
    Replies: 8
    Last Post: 04-05-2005, 10:13 PM
  5. printing large decimal numbers
    By Isometric in forum C++ Programming
    Replies: 5
    Last Post: 03-20-2002, 09:55 PM