Hi, this is probably a very simple problem however I cannot get a valid output from the powl() function. everytime I run it, it gives an output of 0.00. This is probably just a simple usage problem but I can't work out how to raise long double variables to the power of other long double variables. My program is an iterative calculation of pi using 4*(4arctan(1/5)-arctan(1/239). I know you could use the inbuilt arctan functions in math.h but i wanted to make it iterative. I have read the man pages on pow()/powf()/powl() and scoured google but can't get it to work.
sorry for if i'm being thick.
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;
bool sign;
int count;
sign = 0;
count = 0;
divisor = 1;
printf("\n");
while (count < 100) {
if (sign == 0)
{
arctan1 += (( powl( (1/5) , divisor))/divisor );
arctan2 += (( powl ( (1/239) , divisor))/divisor );
sign = 1;
}
else
{
arctan1 -= (( powl ( (1/5) , divisor))/divisor );
arctan2 -= (( powl ( (1/239) , divisor))/divisor );
sign = 0;
}
pi=4*((4*arctan1)-arctan2);
printf("\r%.050Lf", pi);
count++;
divisor +=2;
}
return 0;
}