CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Are there bigger integers than "long long"?

1. Junior Member
Join Date
Feb 2005
Posts
6

## Are there bigger integers than "long long"?

Hi folks,

I scribbled a little c++ program whilst in the bar ;-) last night. It was simply to calculate Fibonacci numbers (you know, the sum of the previous 2)

Basically I calculated up to about the 20th (using a simple int declaration) before the output started "acting up" basically the numbers got too big for a simple int.

I changed the declaration to "long long int" and this got me to the 92nd Fibonacci number before becoming again too large:

89. 2880067194370816120
90. 4660046610375530309
91. 7540113804746346429
92. -6246583658587674878 <----this one added a "-" sign.

Here's the code:

//CODE

#include <iostream>

int main()
{
long long int i1 = 0;
long long int i2 = 1;
long long int fib;

{
for (int x = 1; x <= 92; ++x){
fib = i1 + i2;
std::cout << x;
std::cout << ".";
std::cout << " ";
std::cout << fib << endl;
i1 = i2;
i2 = fib;
}
}
return 0;
}

//CODE

Can I go any higher in calculating these numbers?

Thanks.

Sundodger.

2. Junior Member
Join Date
Feb 2005
Posts
6

## Re: Are there bigger integers than "long long"?

Yup!!

got the syntax wrong for posting code!!

Should have been
Code:
....
. (thanks to dude1967)

3. ## Re: Are there bigger integers than "long long"?

There also is a button below your post, that says "Edit". You can correct your own posts.

As for the integer size, the C++ Standard doesn't say how large the intgral types have to be. Many compilers support __int64 (they may name it something else). For larger ints you'll need to implement them on your own.

4. ## Re: Are there bigger integers than "long long"?

A good free library for big numbers is GMP.
See http://www.swox.com/gmp/

5. ## Re: Are there bigger integers than "long long"?

Aren't __int64 and long long identical in all but naming conventions?
I would use GMP if I could work out how to compile it on MSVC.

6. ## Re: Are there bigger integers than "long long"?

Originally Posted by Improving
Aren't __int64 and long long identical in all but naming conventions?
No, they are not. A long long can have 64 bits, but it isn't required to. The _int64 is a type that always has 64 bits. I'm unsure whether there are standard types with fixed bit sizes (I think there aren't) -- I'm not in the mood right now to look it up

7. ## Re: Are there bigger integers than "long long"?

Originally Posted by Gabriel
The _int64 is a type that always has 64 bits. I'm unsure whether there are standard types with fixed bit sizes (I think there aren't)
C++ standard only says that:

1 = sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

And I think it also says that bool must be represented on 1 byte.

8. Senior Member
Join Date
Apr 2004
Location
Canada
Posts
1,342

## Re: Are there bigger integers than "long long"?

long long and __int64 aren't standard types, only some compilers support them. On the compilers that do support them, __int64 is always 64 bits in size, and long long is typically double the size of long (64-bits if long is 32-bits). I don't know of any compiler supporting built-in integer types larger than 64 bits. If you need to work with larger integers, take a look at some third-party libraries like the GMP library mentioned by olivthill, the apfloat library, or the CBigInt library

9. ## Re: Are there bigger integers than "long long"?

Talking of GMP. Anyone know how to compile this on MSVC or even compile it into a library usable by MSVC with another compiler?

10. ## Re: Are there bigger integers than "long long"?

my suggestion is that should we consider putting it in a singly link list.with the structure containing data field which store parts of the BIgInt,for example,a big integer,123 345 567 890 678 555 456.we contain store 123 in node1,345 in node2,567 in node3,890 in node4,678 in node5.ETC.,and pointer field which maintains the connection of the list.
struct BigIntNode
{
int data;
BigInt*link;
}

regards,
jolley

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)