#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
#include <gmpxx.h>
#include <math.h>

int main(){
  // start with an exponent below 2^32
  int i;
  mpf_class x=2;

  // file output
  FILE *fp1;
  ofstream fp;
  fp.open("cout_test.dat");
  fp1=fopen("gmp_printf_test.dat","w");
  for(i=0;i<40;i++){
    // bug: exponents larger than 2^32 are incorrectly printed with C++ streams
    cout << "cout:\t\t 2^(2^" << i << ") \t= " << x << "\n";
    fp << "fp   :\t\t 2^(2^" << i << ") \t= " << x << "\n";
    // correct exponent with gmp_printf type functions
    gmp_printf("gmp_printf:\t 2^(2^%d) \t= %.*Fg\n",i,6,x.get_mpf_t());
    gmp_fprintf(fp1,"gmp_fprintf:\t 2^(2^%d) \t= %.*Fg\n",i,6,x.get_mpf_t());
    x=x*x;
  }
  fp.close();
  fclose(fp1);
}
