Use a long double, instead of a double. After you've reached your largest data type you can use in your program, you're toast with that program design.
This is a pi approximation from Dr. Math.
Code:
/*
pi.c - computes pi to 4,000 digits. From Dr. Math's website . Minor changes
made to accomodate more digits (up from 800), etc.
*/
#include <stdio.h>
int i = 0;
long int a = 10000,b,c=14000,d,e,f[14001],g; //was 2800 and 2801 for c and f
int main() {
/* Use this code if you want it output to a file called PI.DAT. */
/*FILE *fptr;
if ((fptr = fopen("PI.DAT", "w")) == NULL)
*/
printf("\n\n\n\n");
for (;b-c;) f[b++]=a/5;
/* original line - */
for (;d=0,g=c*2;c-=14, printf("%.4d",e+d/a), e=d%a, i+=4)
/* for file output to PI.DAT */
/* for (;d=0,g=c*2;c-=14, fprintf(fptr,"%.4d",e+d/a), printf("%.4d",e+d/a), e=d%a, i+=4) */
/*
if you change "c-=14 to c-=(any number less than 14) you get a lot more digits.
Eventually, they veer away from the values for Pi, however. (at about 3400 digits.)
*/
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
printf("\nDigits found: %d",i);
/* fclose(fptr); */
printf("\n\n\t\t\t Program Complete - Press Enter When Ready\n");
b = getchar();
return(0);
}
There are faster programs for this, and programs that will give you many more digits of Pi, but they're incomprehensible to me.