Help needed with VERY large numbers.

This is a discussion on Help needed with VERY large numbers. within the C++ Programming forums, part of the General Programming Boards category; I am trying to write a program that does integer math on extremely large numbers. Basically, I'm going to be ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    2

    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?

    Thanks!
    Jeff

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,553
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

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

    [EDIT]
    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 05:34 PM.

  4. #4
    Registered User
    Join Date
    Jan 2004
    Posts
    2
    hrmm...

    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 Google.com, and I found a lot about GMP, but it was all too advanced for me.

    Thanks again!

    jwarner

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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, 08: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, 08:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21