Sharing How to caculate pi upto long-digits
时间:2014-03-17
来源:互联网

10 KEY OFF:CLS

15 INPUT"",SZ:CLS
20 TE=10:IF SZ>200 THEN 30
25 TE=100:SZ=(SZ+1)/2
30 DEF SEG=&HB800

35 CO(1)=25:CO(2)=239
40 '
45 FOR PA = 1 TO 2
50 FOR PL = 0 TO SZ


55 IF PA=1 THEN POKE RE+PL,0
60 NEXT PL

65 IF PA=1 THEN DV=5:GOTO 75
70 DV=239
75 PT=PO:GOSUB 165:EX=1:SI=3-2*PA
80 '
85 FOR PL = 0 TO SZ :POKE TR+PL,PEEK(PO+PL):NEXT PL
90 PT=TR

95 IF SI>0 THEN GOSUB 190
100 IF SI<0 THEN GOSUB 230
105 EX=EX+2:SI=-SI:PT=PO

110 IF PA=2 THEN GOSUB 165
115 IF ZE <>0 THEN GOSUB 125:GOTO 85
120 NEXT PA:GOSUB 125:END
125 '
130 LOCATE 10,6:PRINT
135 PRINT"The value of ";CHR$(227);" up to ";(TE/100+1)*SZ;" decimal place :"

140 FOR PL=RE+1 TO RE+SZ: IF TE=10 THEN 150
145 IF PEEK(PL)<10 THEN PRINT"0";
150 FOR K= 1 TO LEN(STR$(PEEK(PL))):PRINT MID$(STR$(PEEK(PL)),K+1,1);:NEXT K,PL:PRINT
155 RETURN
160 '
165 DI=0:ZE=0
170 FOR PL = PT TO PT +SZ
175 DI=DI+PEEK(PL)


180 RETURN
185 '
190 CA=0
195 FOR PL = SZ TO 0 STEP -1
200 SU=PEEK(RE+PL)+PEEK(TR+PL)+CA:CA=0
205 IF SU<TE THEN 215
210 SU=SU-TE:CA=1
215 POKE RE+PL,SU:NEXT PL
220 RETURN
225 '
230 LO=0
235 FOR PL = SZ TO 0 STEP -1
240 DF =PEEK (RE+PL)-PEEK(TR+PL)-LO

245 IF DF >=0 THEN 255
250 DF =DF +TE

255 POKE RE+PL,DF :NEXT PL
260 RETURN

[ 本帖最后由 西营盘旧街坊 於 2014-3-1 08:26 AM 编辑 ]
作者: 西营盘旧街坊 发布时间: 2014-03-17
作者: 西营盘旧街坊 发布时间: 2014-03-17

作者: 西营盘旧街坊 发布时间: 2014-03-17

作者: me888 发布时间: 2014-03-17
https://www.youtube.com/watch?v=V65mtR08fH0&feature=youtu.be

作者: xianrenb 发布时间: 2014-03-17

作者: me888 发布时间: 2014-03-17
from decimal import Decimal, getcontext
sys.setrecursionlimit(5000)
getcontext().prec = 1500
def find_pi(i, n):
while i<n:
return 1 + i / (Decimal(2.0) * i + 1) * find_pi(i + 1, n)
else:
return 0
print (str(find_pi(Decimal(1), Decimal(3400))*2)[0:1002])
作者: form5 发布时间: 2014-03-17


[ 本帖最后由 me888 於 2014-3-3 10:03 PM 使用 编辑 ]
作者: me888 发布时间: 2014-03-17
后生仔高招!用了recursive function call.



today, people are still using the recursive function to get directory information internally, but adding an iterator outside, so that it looks like a iterative function.
the following C# code is from "mono" library, "Directory.cs"
public static string [] GetDirectories (string path, string searchPattern, SearchOption searchOption)
{
if (searchOption == SearchOption.TopDirectoryOnly)
return GetDirectories (path, searchPattern);
var all = new List<string> ();
GetDirectoriesRecurse (path, searchPattern, all);
return all.ToArray ();
}
static void GetDirectoriesRecurse (string path, string searchPattern, List<string> all)
{
all.AddRange (GetDirectories (path, searchPattern));
foreach (string dir in GetDirectories (path))
GetDirectoriesRecurse (dir, searchPattern, all);
}
...
作者: form5 发布时间: 2014-03-17
http://en.wikipedia.org/wiki/Spigot_algorithm
http://www.mathpropress.com/stan/bibliography/spigot.pdf
在以下网页找到好多种电脑语言产生 Pi 数值的方法:
http://rosettacode.org/wiki/Pi
作者: xianrenb 发布时间: 2014-03-17

作者: me888 发布时间: 2014-03-17
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28