Thread: Really long ints

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    79

    Really long ints

    Hello,

    How could I be able to process extremely long integers? I'm looking to handle integers in the order of 100 million digits..

    Thanks

  2. #2

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    79
    Can I install this on machines that I dont have root access to?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If they don't have a big number library already, persuade the admin it would be a great addition.

    Without root access, I doubt if you can install it.

    Integers with a hundred million digits in them??

    What kind of data are you working with?

    You can program up your own big number program, but it won't be as good as GNU's. Takes time and effort you may not want to spend.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    79
    Um, okay I've had a look at GMP... first thing is first... How could I tell if it's installed on the machine that it's working with... and secondly how would I actually use it? Is there a tutorial available anywhere?

    Thanks

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    79
    Okay I've got the first one cleared I think... the code compiles when I include <gmp.h>, so that probably means that it's installed... But is there a tutorial anywhere as to how I would implement it?

    Thanks

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Wikipedia has two article dealing with it, and then there's this:
    The GNU MP Bignum Library

    What about man command, does it have entries for the gimp?

  8. #8
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Without root access, I doubt if you can install it.
    This can be avoided by compiling with a static version of the library. :P

    As far as tutorials go, there really aren't any. Just take a look at the online docs, it's straightforward.

    1) Create a variable of type mpz_t
    2) Assign it a value via integer, double, or string
    3) Do operations

    The big thing to keep in mind is that GMP is a C library, and does not overload operators. You have to call functions to add/multiply/set mpz_t. It's all explained in great detail in the manual though so you shouldn't have any trouble.
    Consider this post signed

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Why would you need root access to install a library? Just place it someplace in your home directory, then set LD_LIBRARY_PATH when you run the application that requires the library.
    bit∙hub [bit-huhb] n. A source and destination for information.

  10. #10
    Registered User
    Join Date
    Jul 2009
    Posts
    36
    Quote Originally Posted by bernt View Post
    The big thing to keep in mind is that GMP is a C library, and does not overload operators. You have to call functions to add/multiply/set mpz_t.
    I know this is the C forum, but if you can use C++, GMP has a C++ interface which is much easier to work with. You declare a integer variable like "mpz_class myInt;" and then you can use all the normal C operators instead of calling the mpz* functions (e.g., myInt*=2; etc.). The C++ interface is documented in the GMP manual.

    I have an article that has some GMP examples -- both in C and C++ -- which shows how to work with both integers and floating-point numbers: How to Install and Run GMP on Windows Using MPIR - Exploring Binary (ignore the part about installing, since it sounds like you have it installed and are probably on Linux and not Windows anyhow -- just jump to the end for the examples).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic optimization request...
    By feeder74 in forum C++ Programming
    Replies: 27
    Last Post: 05-05-2010, 07:17 AM
  2. Seg Faults with XOR LL
    By seePhor in forum C Programming
    Replies: 5
    Last Post: 03-12-2010, 12:20 AM
  3. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  4. Merge and Heap..which is really faster
    By silicon in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2005, 04:06 PM
  5. Insertion Sort Problem
    By silicon in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2005, 12:30 PM