thank you very much for your help, as you've probably guessed, i'm extremely new to C programming.
ok last question (sorry)
how can I implement more precision than long double, because after 20 iterations it doesn't seem to change the value of pi. i'm guessing this is due to rounding due to it running out of usable bits in memory. (maybe i'm wrong)
i've heard about __float128 but i'm not sure if this would be tricky to implement, there's not much i can find about it.
Code:
/*
program works by working out pi as 4*(4arctan(1/5)-arctan(1/239)
it approximates arctan(z) as (z^1)/1-(z^3)/3+(z^5)/5-...
*/
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int main (int argc, const char * argv[]) {
long double pi, arctan1, arctan2, divisor, a, b;
bool sign;
int count;
a = (1.0)/(5.0);
b = (1.0)/(239.0);
sign = 0;
count = 0;
divisor = 1;
printf("\n");
while (count < 2000) {
if (sign == 0)
{
arctan1 += (( powl ( a , divisor))/divisor );
arctan2 += (( powl ( b , divisor))/divisor );
sign = 1;
}
else
{
arctan1 -= (( powl ( a , divisor))/divisor );
arctan2 -= (( powl ( b , divisor))/divisor );
sign = 0;
}
pi=4*((4*arctan1)-arctan2);
printf("%.0100Lf\n", pi);
count++;
divisor +=2;
}
printf("\n");
return 0;
}