How to get past the limit of an int?

This is a discussion on How to get past the limit of an int? within the C++ Programming forums, part of the General Programming Boards category; Can you make an int greater than 2 ^ 31 - 1 (2,147,483,647)? Or is there a class you can ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Location
    HOLLAND
    Posts
    10

    How to get past the limit of an int?

    Can you make an int greater than 2 ^ 31 - 1 (2,147,483,647)? Or is there a class you can use for that purpose? I can't use a double or a float.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    unsigned long will increase the range somewhat but if you want to go higher than that you need something like http://swox.com/gmp/
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    C99 called just to say "long long".


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Thats C only and this is the c++ board.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Aug 2005
    Location
    HOLLAND
    Posts
    10
    Thanx for the awnsers, but i've downloaded the gmp software, and i don't understand how to use it. Could you maybe give a short explanation?

    Quzah: I use classes and other C++ specific things in my program...

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    read the manual. It contains plenty of installation info for mingw and gcc. If you use MSVC you can use MinGW to build a lib that can be used with MSVC. Theres some instructions in the manual. For use of the library once built see the documentation and samples.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You might want to search for other, C++ specific large integer classes, or even C++ wrappers for GMP, if they are out there.

    From my experience, if you have a lot of number crunching to do, the C function-based syntax of GMP can be a royal pain (sorry Quzah).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    51
    Make your own integer class! Or use gmp if you don't want a mountain of extra work.
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Stoned_Coder
    Thats C only and this is the c++ board.
    Some people have no sense of humor. I guess I won't bother telling you that Java's long is 64 bits, since you wouldn't find that amusing either.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Not to mention that gcc supports long long in C++ and VS.NET supports some other weird name, and you can always use typedefs for portability.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    VC++ supports __int64 for 64 bit integers.

  12. #12
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Quote Originally Posted by quzah
    C99 called just to say "long long".
    Quote Originally Posted by quzah
    Some people have no sense of humor. I guess I won't bother telling you that Java's long is 64 bits, since you wouldn't find that amusing either.
    He merely mistook C99 for a telemarketer... honest mistake.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  13. #13
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    It seems everyone but Daved forgot to mention __int64, which is what I was going to suggest. If you need to get even bigger than that max you can use unsigned __int64.

    Also, you can use my HugeFloat library for "unlimited" length numbers and rapid calculations. And it is as easy to use as a built-in type. Just click on that link or visit the library page on my site (see sig).

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    The reason I didnt mention __int64 is because it is m$ specific. I also knew that long long was a popular extension offered on gcc but that is specific to that compiler. Typedefs and conditional compilation could solve the problem but the more compilers you need to support the more like a spiders web your code looks. When you need numbers bigger than the language supports natively you should reach for a library if portability is any concern at all. There are numerous bignum libraries out there and there is a fair chance that a bignum library will be added to c++ at the next standard review.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    __int64 is not specific to Microsoft. __int64 is not one of the standard 5 integer types (according to C99 section 6.2.5 paragraph 4), but it is a legal ISO/ANSI extended integer type as defined by that same paragraph.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:26 PM
  2. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM

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