高精度减法

来源:互联网 发布:网络路演 编辑:程序博客网 时间:2024/05/15 07:42

方便调用,直接写成了高精度减法的函数

function gjdjfa(a,b:ansistring):ansistring;var d:ansistring;  c:array[1..10000]of ansistring;  i,max,m,n,x,y,code,z,right,count1:longint;begin  for i:=1 to 10000 do  c[i]:='a';  m:=length(a);  n:=length(b);  for i:=1 to m do  if pos(' ',a)<>0 then delete(a,pos(' ',a),1);  for i:=1 to n do  if pos(' ',b)<>0 then delete(b,pos(' ',b),1);  m:=length(a);  n:=length(b);  if m>n then  begin  max:=m;  for i:=1 to m-n do  b:='0'+b;  end  else if m<n then  begin  max:=n;  for i:=1 to n-m do  a:='0'+a;  end  else max:=m;  for i:= 1 to max do  begin    val(a[max-i+1],x,code);    val(b[max-i+1],y,code);    if max=n then    begin    count1:=y-x-z;    right:=1;end    else  count1:=x-y-z ;if count1>=0 then    begin      str(count1,c[i]);      z:=0;end    else    begin      str(count1+10,c[i]);      z:=1;    end;  end;  for i:=10000 downto 1 do  begin    if c[i]='a' then  d:=d    else d:=d+c[i];  end;  if right=1 then d:='-'+d;  if( m-n>0)and (copy(d,1,1)='0') then delete(d,1,m-n);  exit(d);end;



0 0