as mentioned in the question, I use recursion to calculate the approximate value of PI: PI/4 = 1-1 PI 3 + 1 hand 7 + 1 hand 9 +;
code is as follows:
let calPI = (n, sum = 1)=> {
if(n < 3)
return sum*4;
n%4 === 1 ? sum += 1/n : sum -= 1/n;
return calPI(n-2, sum);
}
console.log(calPI(99999));
calPI (9999)
there is no stack overflow. Am I writing something wrong?