Like Tree1Likes
  • 1 Post By LyTning94

Storing numbers larger than long long

This is a discussion on Storing numbers larger than long long within the C++ Programming forums, part of the General Programming Boards category; Is there a library out there that lets you store numbers that are too big for a long long? This ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    61

    Storing numbers larger than long long

    Is there a library out there that lets you store numbers that are too big for a long long? This is all theoretical--I don't actually have a use for it, I'm just wondering if it's out there.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,436
    Yes. For example: GMP. Of course, if you are just storing the numbers, then storing them as strings could suffice.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    Some of us even write our own classes for dealing with large numbers.
    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"

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Quote Originally Posted by laserlight View Post
    Yes. For example: GMP. Of course, if you are just storing the numbers, then storing them as strings could suffice.
    I tried to compile GMP on cygwin, but I'm getting the following errors:

    /usr/bin/sed: can't read programming/gmp-5.0.5/libgmp.la: No such file or directory
    libtool: link: `programming/gmp-5.0.5/libgmp.la' is not a valid libtool archive
    Makefile:752: recipe for target `libgmpxx.la' failed
    make[2]: *** [libgmpxx.la] Error 1
    make[2]: Leaving directory `/cygdrive/c/users/user/desktop/c++ programming/gmp-5.0.5'
    Makefile:924: recipe for target `all-recursive' failed
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/cygdrive/c/users/user/c++ programming/gmp-5.0.5'
    Makefile:659: recipe for target `all' failed
    make: *** [all] Error 2
    I checked, and the file libgmp.la does exist at that path. I used

    ./configure --enable-cxx
    make

    to compile.

  5. #5
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    In my experience, compiling GMP on Windows is a real pain. I tried doing it using MSYS a while ago and ended up abandoning the idea.

    A quick google search turned up this:
    apfloat for C++

    Seems worth a try, there are other bignum libraries out there aswell, the above is for real numbers, if you want specifically for integers i believe there is one called bigint-cpp, which is object oriented as well.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,436
    Quote Originally Posted by LyTning94
    I tried to compile GMP on cygwin, but I'm getting the following errors:
    Have you tried placing the library source on a path that does not contain spaces? I have heard that such embedded spaces may cause problems for MinGW, and maybe the same applies for Cygwin.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    It sounds like you do have a use for it after all, otherwise you probably wouldn't bother trying to get it to work

    I do like to encourage others to learn how to get other libraries out there for this working, as it alone can be useful for learning more about how to integrate with these sorts of things. However, I don't ever use the build environment you are using and cant really help in that area.

    Did I mention that I maintain my own which is hosted on my website (link below)? It's just one header file. That's it, nothing else, just one file, and one I can certainly help with. If you just want something up and running quickly, to play around with, then by all means give it a go. I don't get anything out of it other than motivation to continue improving it.

    If you'd rather go with one of those large packages that do everything but might be harder to use, the following link has several listed:
    Arbitrary-precision arithmetic - Wikipedia, the free encyclopedia
    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"

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Quote Originally Posted by laserlight View Post
    Have you tried placing the library source on a path that does not contain spaces? I have heard that such embedded spaces may cause problems for MinGW, and maybe the same applies for Cygwin.
    I tried this, and it appears to compile fine. I ran 'make check' and all the tests were successful. I then ran 'make install', which as far as I can tell should have installed the .lib file to cygwin/usr/local/lib. I looked there, and the only files there are libgmp.a, libgmp.la, libgmpxx.a, and libgmpxx.la. What are the .a and .la files, and where is the .lib?

    @iMalc
    Because at the moment I don't have an actual use for it, and am just exploring the possibilities, I'd rather go with a library that has more features, even if it is a pain to set up.
    Last edited by LyTning94; 06-01-2012 at 11:44 AM.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,436
    Quote Originally Posted by LyTning94
    I then ran 'make install', which as far as I can tell should have installed the .lib file to cygwin/usr/local/lib. I looked there, and the only files there are libgmp.a, libgmp.la, libgmpxx.a, and libgmpxx.la. What are the .a and .la files, and where is the .lib?
    These are your library archives, i.e., there is no .lib file. You can link to libgmp.a by passing -lgmp to gcc.

    EDIT:
    Oh wait, C++. I have forgotten exactly what, but you probably should pass -lgmpxx to g++ then, possibly in addition to -lgmp, especially if you want to use the C++ class wrapper.
    Last edited by laserlight; 06-01-2012 at 12:08 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Quote Originally Posted by laserlight View Post
    These are your library archives, i.e., there is no .lib file. You can link to libgmp.a by passing -lgmp to gcc.

    EDIT:
    Oh wait, C++. I have forgotten exactly what, but you probably should pass -lgmpxx to g++ then, possibly in addition to -lgmp, especially if you want to use the C++ class wrapper.
    Okay...is there any way to link to this file in VC++?

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,436
    Quote Originally Posted by LyTning94
    Okay...is there any way to link to this file in VC++?
    Refer to the docs on Notes for Particular Systems. Basically, you would need to build using MinGW instead to get a DLL from which you can create the .lib file.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    Quote Originally Posted by LyTning94 View Post
    Because at the moment I don't have an actual use for it, and am just exploring the possibilities, I'd rather go with a library that has more features, even if it is a pain to set up.
    Best of luck to you then.
    Let us know how it goes, and if you end up using one of libraries for something, feel free to drop in and tell us what it was and how it went.
    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"

  13. #13
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    I thought I'd just download MathX, one of the newer ones mentioned on the wikipedia article I linked to, that I hadn't seen before.
    Turns out that its quite similar, but rather primitive feature-wise compared to mine, and uses far slower methods of multiplication and division. (Mine has been around 6 years longer)
    It's does some weird thing that I considered a while ago where an N-bit integer is composed of two N/2 bit integers, using the same class in most cases. I decided that idea was crazy, and now that I've seen it done, I don't think it was any less crazy than I imagined.
    I can't believe it does unary minus by a multiplication by -1, invoking the slow multiplication algorithm. What on earth was this guy thinking!

    The code has way better commenting than mine, and it does look about as easy to use, but with its feature set so tiny, I imagine it wont suit your needs.
    Actually, I'm just writing a review of it on sourceforge now...
    Last edited by iMalc; 06-01-2012 at 03:47 PM.
    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"

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    While looking for ways to compile GMP in VC++, I stumbled across MPIR, which is a Windows-based version of GMP. I compiled that in VC++ and everything worked great. I haven't tried it out yet, but the .lib file is there.
    laserlight likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing a long type in an array....
    By Nyah Check in forum C Programming
    Replies: 3
    Last Post: 03-30-2012, 01:01 PM
  2. Storing a very long number
    By valthyx in forum C Programming
    Replies: 21
    Last Post: 08-08-2011, 12:52 PM
  3. Replies: 1
    Last Post: 04-23-2011, 08:40 PM
  4. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  5. Storing long strings?
    By thebudbottle in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2005, 05:10 PM

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