double with a 300-digit number

Hi!

I have written a program which prints out a certain number.
the thing is, when a number is greater then 8 digits, it returns x.xxxxe+00x
where the x are some random numbers and I want it to write all the numbers, and I've tried with the command "fixed" and "setprecision" and combos of those two, but every number beyond the 8:th digit is a 0, how can I make it write all the digits of a number?

#include <iostream>
#include <conio.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include<fstream>


using namespace std;
unsigned long double M,x,n;
ofstream spara;

int main()
{
do{
cout<<"Mata in hur manga mersenne-tal som ska visas"<<endl;
cin>>n;

for(x=0;x!=(n+1);x++)
{
M=pow(2,n)-1;
cout<<M<<endl;
spara.open("Mersenne.txt",ios::app);
spara <<"n="<<n<<" "<<M<<endl;
spara.close();
}
}while (n!=0);
return 0;


}
Floating-point numbers don't work that way. They essentially approximate a number.

Especially if you are playing with Mersenne primes, you will want to use a Bignum library.

GNU MP Bignum Library
http://gmplib.org/

Hope this helps.
Last edited on
Okay, thanks! I'll try that and se if it gives any result :)
Topic archived. No new replies allowed.