man bc帮助信息中的一段:
In /bin/sh, the following will assign the value of "pi" to the shell variable pi.
pi=$(echo "scale=10; 4*a(1)" | bc -l)
∵tan(PI/4) = 1
∴ PI = 4*atan(1)
bc 命令加上 -l 参数,就可以使用sin/cos/atan等数学函数。a (x) 就是计算 atan() 反正切值;
bc中,scale=100 表示控制计算结果的小数点后面的位数;
所以,echo "scale=5000; 4*a(1)" | bc -l 这个命令就可以表示计算PI保留小数点后5千位小数。
加上time命令对PI计算过程计时
time echo "scale=5000; 4*a(1)" | bc -l
可以测试单核CPU的计算能力