23万UV达成

As of 2023-11-09.

Cosmopolitan

神奇。

π

简单代码计算圆周率,原理有人做视频解释了。

1
2
3
#include <stdio.h>
int a[52514],b,c=52514,d,e,f=1e4,g,h;int main(){for(;b=c-=14;h=printf("%04d",
e+d/f))for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;}

我试了,计算15000位需要0.4 s。如果用支持高精度计算的bc实现同样的效果需要大约1分钟。

1
time bc -l <<< "scale=15000;16*a(1/5) - 4*a(1/239)"

嗯,有没有一种能用bc实现的高效的算法呢?

https://en.wikipedia.org/wiki/Chudnovsky_algorithm

https://www.craig-wood.com/nick/articles/pi-chudnovsky/

https://www.mathworks.com/company/technical-articles/computing-pi.html

高效的算法,即便是用Python这种相对低效的语言实现,也足够快。

HUAWEI nova 11 SE

2025-03-08 Update:

大概1年后,苹果也出了iPhone 16e,名字也带e,有视频说这手机是为美国的合约机用户准备的