Delphi快速加大整数? [英] Delphi fast plus big integer?
本文介绍了Delphi快速加大整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function AddNumStrings (Str1, Str2 : string): string;
var
i : integer;
carryStr : string;
worker : integer;
workerStr,s : string;
begin
Result := inttostr (length(Str1));
Result := '';
carryStr := '0';
// make numbers the same length
s:=StringofChar('0',Length(Str1)-1);
Str2:=s+Str2;
i := 0;
while i < length(Str1) do
begin
worker := strtoint(copy(Str1, length(str1)-i, 1)) +
strtoint(copy(Str2, length(str2)-i, 1)) +
strtoint (carryStr);
if worker > 9 then
begin
workerStr := inttostr(worker);
carryStr := copy(workerStr, 1, 1);
result := copy(workerStr, 2, 1) + result;
end
else
begin
result := inttostr(worker) + result;
carryStr := '0';
end;
inc(i);
end; { while }
if carryStr <> '0' then
result := carryStr + result;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s,z:String;
begin
s:='1000';
repeat
s:=AddNumStrings(s,'1');
until
Length(s)=1000;
ShowMessage(s);
end;
end.
但是此代码花费的时间太长。我的代码是否可以选择最快的方式?
我正在大量工作,所以我必须手动编写 Inc()过程来处理十亿位数。我知道您对此有何看法,但我必须这样做。谢谢。
But this codes takes too time. Is there any options to fastest way for my codes? I m working huge number so I have to write "Inc()" procedure manually for huge number billion digits. I know what you think about it bu I have to do it. Thank you..
推荐答案
- FPC的 INT128 lib
- GNURZ lib(适用于FPC,但应与Delphi兼容)
- GMP (FPC 支持,Delphi )
- BigInt 和 BigFloat
- BigInt Delphi库
- 另一个 BigInt
- TPMath
- DeHL for Delphi
- BigNumbers BigInteger ,BigDecimal和BigRational for Delphi
- INT128 lib for FPC
- GNURZ lib (for FPC but should be compatible with Delphi)
- GMP (FPC supports it, Delphi also)
- BigInt and BigFloat
- BigInt Delphi Library
- Another BigInt
- TPMath
- DeHL for Delphi
- BigNumbers BigInteger, BigDecimal and BigRational for Delphi
希望其中之一会更快...
Hopefully one of those will be faster...
这篇关于Delphi快速加大整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文