这段代码如何高精度地计算圆周率?

How does this code calculate pi with high precision?

代码如下:

#include <stdio.h>

long f[2801];

int main()
{
    long i = 0, c = 2800, d = 0, e = 0, g = 0;
    for (i = 0; i < c; ++i)
        f[i] = 2000;
    for (;;) {
        d = 0; 
        g = c * 2;
        if (!g)
            break;
        i = c;
        for(;;) {
            d += f[i] * 10000;
            --g;
            f[i] = d % g;
            d /= g;
            --g;
            --i;
            if (!i) break;
            d *= i;
        }
        printf("%.4ld",e+d/10000);
        e = d % 10000;
        c -= 14;
    }
    return 0;
}

我的问题是:这段代码如何计算小数点精度高的圆周率,它使用的数学公式是什么?

这是荷兰 CWI 研究所的 Dik T. Winter 编写的 PI 程序的格式化副本。最初以混淆形式编写,两行或三行,Dik 和其他人根据数学序列的评估输出不同数量的 PI(例如 800、15,000 等)有多种变体。

它是一个 class 程序,称为 'spigot algorithms',旨在输出特定数量的数字。您可以通过 Google 搜索 Dik Winter 和 'spigot algorithms' 找到更多信息。一些示例命中:

Computing Pi in C算法的详细分析,有未解答的问题。

Pi the Number, not the Movie