Really large numbers Fibonacci sequence past 93

For fun, and a love of numbers, I wrote a very simple program that desplays all the numbers in the Fibonacci sequence upto x number. It of course ends the loop if the number becomes larger then the the used variable type.

In my program I use unsigned __int64 because out of all the type I found it allowed the largest number. My question is:
How can I allow for my program to reach values larger than the 93rd number in the sequence?

I have googled and found an idea to use classes, which I dont really understand.
http://www.codeproject.com/KB/cpp/largenumber.aspx

Is there another way to use super large numbers greater than 10^19?

Also, what is the difference between unsigned __int64 and unsigned long long?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>

using namespace std;

unsigned __int64 x = 1;
unsigned __int64 y;
unsigned __int64 z;
int a;
int b;
int c=0;


int main()
{
    cout << "Find how many numbers? \n";
    cin >> a;

    for (b=0;b<a;b++)
    {
        if (b%3==0)
        {
            c++;
            cout <<"\n" << c << ") ";
        }

        cout << x << "  ";
        z = y;
        y = x;
        x +=z;
        
        if (x < z)
        {
             cout << "\nMaxed out at " << b+1;
             b = a;
        }



    } // for
cin.get();
cin.get();
}
Last edited on
I dont think there's any way to do that other than create a class which can handle large "numbers" (individual digits stored as vectors, perhaps). Its one of the projects I'm working on atm.
Google around "c++ bignum". There are a few good libraries out there.

The GNU MP Bignum Library is very good. It is distributed under the LGPL so you can use it without having to GPL your own code.
http://gmplib.org/

I also like the TTMath library --for ix86 architecture.
http://ttmath.slimaczek.pl/ttmath

As for types, that is actually a compiler-dependant question. You should be able to #include <cstdint> to get a complete range of types. See Wikipedia for more:
http://en.wikipedia.org/wiki/Stdint.h

Hope this helps.
Duoas,
Great reply. Those links show me exactly what I need. Thank you.
Topic archived. No new replies allowed.