Precision limited to 16 decimal places

I wrote the following program to compute pi. The problem is that I want to show more than 16 decimal places worth of accuracy and the out put shows the 16 decimal places and the remaining places set by 'setprecision' are filled with zeros.

The code:
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{
double temp;
double temp2;
double k;
double pi;

k = 0.0;
temp = 0.0;
temp2 = 0.0;
iterate = 0;
pi = 3.1415926535897932384626433832795028841971;

cout.precision(20);

cout << "Calculate the value of pi using a transformation of the Madhava-Liebniz series." << endl;

for(k=0; temp2!=pi; k++)
{
temp = temp2;
temp2 = temp + (sqrt(12.0)*pow(-3.0,-k))/(2*k+1);
}

cout << showpoint << "pi = " << temp2 << endl;
cout << noshowpoint << "k = " << k << endl;

return 0;
}

The output:
Calculate the value of pi using a transformation of the Madhava-Liebniz series.
pi = 3.1415926535897931000
k = 30
Press any key to continue . . .

Notice the zeros from 17th to 20th decimal place. I would like to see this go to 40 decimal places. If anyone can offer any advice, I'd appreciate it.
that number is too large to fit in a double, so you're losing precision.

If you want more precision, you'll have to use a different variable. For this, you'd probably need a bignum lib.

Google "bignum lib". I think it's the first hit.
Topic archived. No new replies allowed.