我大体上考虑了一下用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
1<add2pend add1pend="" if="" longtable.bookmark:="ypeof;" then="">=add2pend then longtable.bookmark:=xpeof;
2while not bof() do begin//////##
3if (longtable.recno<add1pend) (longtable.recno="" and="">add2pend)then begin
4fields(sump):=fields(add2p);longtable.prior;continue;
5end;
6if (longtable.recno<add2pend) and(longtable.recno="">add1pend) then begin
7fields(sump):=fields(add1p);longtable.prior;continue;
8end;
9temp:=fields(add1p)+fields(add2p);
10if (jump=1) then begin
11temp:=temp+1;
12jump:=0;
13end;
14if (temp>=10) then begin
15fields(sump):=temp-10;jump:=1;end;
16if temp<10 then fields(sump):=temp;
17longtable.prior;
18end;//////##
19while not longtable.recno>max(add1iend,add2iend) do begin//@@
20if (longtable.recno>min(add1iend,add2iend)) and (add1iend<add2iend)then (longtable.recno="" begin="" end;="" fields(sumi):="fields(add2i);longtable.next;continue;" if="">min(add1iend,add2iend)) and(add1iend>add2iend) then begin
21fields(sumi):=fields(add1i);longtable.next;continue;
22end;
23temp:=fields(add1i)+fields(add2i);
24if (jump=1) then begin
25temp:=temp+1;
26jump:=0;
27end;
28if (temp>=10) then begin
29fields(sumi):=temp-10;jump:=1;end;
30if temp<10 then fields(sumi):=temp;
31longtable.next;
32end;//@@
33
34end;////</add2iend)then></add2pend)></add1pend)></add2pend>