计算PI值到一亿位的算法

类别:Delphi 点击:0 评论:0 推荐:

我大体上考虑了一下用DELPHI计算PI值到一亿位的算法,得到一个大体的算法,也好用来交流一下。这是一个构造一种新的长四则运算的算法。所谓长四则运算,是指用数据库的字段来作一个小数,用一个记录来作一个小数数位的算法。先作出longadd(),longsub(),longmulti(),longdiv(),然后再用求PI公式来求即可。下面我大体上作出了longadd(),并尚未经过上机调试的。先作六个全局书签变量:
public
Xieof,Xpeof,Yieof,Ypeof,Zieof,Zpeof:Tbookmarkstr;
procedure longadd(add1,add2,sum:integer);//字段的索引值。
var
add1i,add1p,add2i,add2p,sumi,sump:integer;
add1iend,add1pend,add2iend,add2pend,temp,jump:integer;
begin////
add1i:=add1;add1p:=add1+1;add2i:=add2;add2p:=add2+1;
sumi:=sum;sump:=sum+1;temp:=0;jump:=0;//初值,字段的索引值。
longtable.bookmark:=xpeof;add1pend:=longtable.recno;
longtable.bookmark:=ypeof;add2pend:=longtable.recno;
if add1pend<add2pend  then  longtable.bookmark:=ypeof;
if add1pend>=add2pend then  longtable.bookmark:=xpeof;
while not bof()  do begin//////##
if (longtable.recno<add1pend) and (longtable.recno>add2pend)then  begin
fields(sump):=fields(add2p);longtable.prior;continue;
end;
if (longtable.recno<add2pend) and(longtable.recno>add1pend) then  begin
fields(sump):=fields(add1p);longtable.prior;continue;
end;
temp:=fields(add1p)+fields(add2p);
if  (jump=1) then begin
temp:=temp+1;
jump:=0;
end;
if (temp>=10)  then  begin
fields(sump):=temp-10;jump:=1;end;
if temp<10 then  fields(sump):=temp;
longtable.prior;
end;//////##
while not longtable.recno>max(add1iend,add2iend) do begin//@@
if (longtable.recno>min(add1iend,add2iend)) and (add1iend<add2iend)then  begin
fields(sumi):=fields(add2i);longtable.next;continue;
end;
if (longtable.recno>min(add1iend,add2iend)) and(add1iend>add2iend) then  begin
fields(sumi):=fields(add1i);longtable.next;continue;
end;
temp:=fields(add1i)+fields(add2i);
if  (jump=1) then begin
temp:=temp+1;
jump:=0;
end;
if (temp>=10)  then  begin
fields(sumi):=temp-10;jump:=1;end;
if temp<10 then  fields(sumi):=temp;
longtable.next;
end;//@@

end;////

本文地址:http://com.8s8s.com/it/it5337.htm