-
August 26th, 2005, 04:58 AM
#1
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.
-
August 26th, 2005, 05:00 AM
#2
Re: Are there bigger integers than "long long"?
Yup!!
got the syntax wrong for posting code!!
Should have been . (thanks to dude1967)
-
August 26th, 2005, 05:38 AM
#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.
-
August 26th, 2005, 06:07 AM
#4
Re: Are there bigger integers than "long long"?
A good free library for big numbers is GMP.
See http://www.swox.com/gmp/
-
August 26th, 2005, 01:08 PM
#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.
Hungarian notation is the bane of self documenting code.
Forget all fancy tricks with operator precedence. Code should be easily readable.
May the BOOST be with you.
Good free E-Books thanks to Bruce Eckel.
-
August 26th, 2005, 03:07 PM
#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
-
August 26th, 2005, 03:42 PM
#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.
-
August 26th, 2005, 05:11 PM
#8
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
Old Unix programmers never die, they just mv to /dev/null
-
August 26th, 2005, 08:44 PM
#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?
Hungarian notation is the bane of self documenting code.
Forget all fancy tricks with operator precedence. Code should be easily readable.
May the BOOST be with you.
Good free E-Books thanks to Bruce Eckel.
-
August 26th, 2005, 11:53 PM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|