/** Print ascending members of the Fibonacci sequence that are
representable as 64-bit signed integers, prefixed by their term
numbers, and followed by the ratio of successive terms, to
demonstrate the 1.618...^n growth (the ratio approaches the golden
ratio, (1 + sqrt(5))/2 = 1.6180339887498949, and reaches it (to
machine precision) at 41 terms: the fourth item on each line is
the difference from the golden ratio). */

#if defined(__osf__)
#define __USE_STD_IOSTREAM 1	// needed to access I/O manipulators
#endif

#include <iomanip.h>
#include <iostream.h>
#include <math.h>
#include <stdlib.h>

#if defined(__osf__)
#include <iosbase>
#endif

#include <ios>

int
main(void)
{
    long long lo = 1LL;
    long long hi = 1LL;
    long long n = 1LL;
    double ratio;
    const double golden_ratio = (1.0 + sqrt(5.0))/2.0;

    cout << setw(2) << n << "\t" << setw(19) << lo << endl;

    while (hi > 0LL)
    {
	n++;
	ratio = (double)hi/(double)lo;
	cout << setw(2) << n << "\t" << setw(19) << hi << "\t" 
	     << setprecision(15) 
	     << fixed << setw(19) << ratio << "\t" 
	     << fixed << setw(19) << (ratio - golden_ratio) << endl;
	hi = lo + hi;
	lo = hi - lo;
    }
    return (EXIT_SUCCESS);
}
