万宝鱼的三湖樱桃:在Pascal里,有没有比longint长整型更长的类型?

来源:百度文库 编辑:高校问答 时间:2024/04/28 02:18:16
在Pascal里,有没有比longint长整型更长的类型?
如果是turbo pascal呢?

用高精度运算.范围是10^255以内!
程序:
program gjd;
var
s1,s2,result:string;
function clear(s:string):string;
begin
while (length(s)>0) and ((s[1]=' ')or(s[1]='0')) do delete(s,1,1);
if s='' then s:='0';
clear:=s;
end; {clear}
function bigger(s1,s2:string):boolean;
begin
bigger:=true;
if length(s1)>length(s2) then exit;
if (length(s1)=length(s2))and (s1>=s2) then exit;
bigger:=false;
end;{bigger}

function addition(s1,s2:string):string;
var
i:integer;
begin
while length(s1)< length(s2) do s1:='0'+s1;
while length(s2)< length(s1) do s2:='0'+s2;
s1:='0'+s1; s2:='0'+s2;
for i:=length(s1) downto 1 do begin
inc(s1[i], ord(s2[i])-ord('0'));
if s1[i]>'9' then begin
dec(s1[i],10);
inc(s1[i-1]);
end;
end;
addition:=clear(s1);
end;{addition}

function subtraction(s1,s2:string):string;
var
i:integer;
begin
while (length(s1)< length(s2)) do s1:='0' +s1;
while (length(s2)< length(s1)) do s2:='0' +s2;
for i:=length(s1) downto 1 do
if s1[i]>= s2[i] then
dec(s1[i],ord(s2[i])-ord('0'))
else begin
inc(s1[i],10);
dec(s1[i-1]);
dec(s1[i],ord(s2[i])-ord('0'));
end;
subtraction:=clear(s1);
end; {subtraction}

function multiply(s1,s2:string):string;
var
i:integer; c:char;
begin
result:='0';
for i:=length(s2) downto 1 do begin
for c:='1' to s2[i] do
result:=addition(result, s1);
s1:=s1 + '0';
end;
result:= clear(result);
multiply:=result;
end; {multiply}

function division(s1,s2:string):string;
var
i:integer; s:string;
begin
result:='';
s:='';
for i:=1 to length(s1) do
begin
s:=s+s1[i];
result:=result+ '0';
while bigger(s,s2) do
begin
inc(result[length(result)]);
s:=subtraction(s,s2);
end;
end;
division:=clear(result);
end; {function}

begin
write('a=');
readln(s1);
write('b=');
readln(s2);
s1:=clear(s1);
s2:=clear(s2);
writeln('a>b? ',bigger(s1,s2));
writeln('a+b=',addition(s1,s2));
writeln('a-b=',subtraction(s1,s2));
writeln('a*b=',multiply(s1,s2));
writeln('a/b=',division(s1,s2));
readln;
end.

我用的都是int64,int64可以处理2^54,不过楼主随便

补充:
int64:-9223372036854775808..9223372036854775807
qword:0..184467440703709551615

整型:comp
实数型:extended


int64,qword,dword
comp,extended


int64,qword,dword