News for hackers. Stuff that matters.
Re:Show HN: Every Day Is Pi Day by partycoder on Tuesday March 14, 2017 @12:15PM (#13868788)
An approximation of Pi I put together just now

    var i, a = 1, s = false;
    var steps = 10000000000;

    for (i = 3; i < steps; i += 2) {
	a += s ? 1/i : -1/i;
	s = !s;
    }

    console.log(a * 4);
That loop approximates arctan(1) with a Taylor series, only using basic arithmetic operations.

    pi = arctan(1) * 4
Outputs:

    3.141592653388201
              ^-- last correct digit

There are no comments on this comment yet.