TIntX O(N * log N) 곱셈/디비전 알고리즘 구현에 대한 FAST를 갖춘 Intx 임의의 정밀 정수 라이브러리의 파스칼 포트입니다. 정수에 대한 모든 기본 산술 작업, 비교, 비트 시프트 등을 제공합니다. 또한 다른베이스에서 숫자를 구문 분석하고 모든베이스에서 문자열로 변환 할 수 있습니다. 이 라이브러리의 장점은 빠른 곱셈, 분할 및 기본/기본 변환 알고리즘입니다. 알고리즘의 모든 빠른 버전은 고전적인 O(N^2) 대신 O(N * log N * log log N) 시간을 실행하는 빠른 Hartley 변환을 사용하여 큰 정수의 빠른 곱셈을 기반으로합니다.
상태 빌드 상태
다음은 TIntX 사용하여 Power 1048576 (2^20 (1 shl 20))에서 42를 계산하는 코드 샘플입니다.
uses // including only the non-obvious
SysUtils, uIntX, uEnums;
procedure Calc ();
var
valA, valB: UInt32;
Delta: Double;
begin
valA := GetTickCount;
TIntX. Pow ( 42 , 1048576 );
valB := GetTickCount;
Delta := (valB - valA) / 1000 ;
ShowMessage(Format( ' time elapsed is %f seconds ' , [Delta]));
end ;
procedure TForm1.Button1Click (Sender: TObject);
begin
Calc();
TIntX.GlobalSettings.MultiplyMode := TMultiplyMode.mmClassic;
Calc();
end ; First 'Calc()' call uses fast multiplication implementation (which is default),
second, classic one. On my machine (Windows 10 Update 2, Intel Core i3 2.53 GHz,
6 GB RAM), Compiled with 64 bits, first call took 0.30 seconds while the second one
took 17.91 seconds.Resulting number has 1,702,101 digits.
내 내부적으로 구현 된 다른 기능은 나와 내부적으로 구현됩니다
IntegerSquareRoot (Integer SquareRoot)
Square
GCD (Greatest Common Divisor (HCF))
LCM (Least Common Multiple)
AbsoluteValue (Get Absolute Value of a Negative TIntX)
Bézouts Identity
InvMod (Modular Inverse)
Factorial
IntegerLogN (base, number) (Gets IntegerLog of a number using a specified base)
Ln (The natural logarithm)
Log10 (The base-10 logarithm)
LogN (Logarithm of a number for a specified base)
Random (Now Uses PcgRandom Instead of Mersemme Twister)
Modular Exponentiation (ModPow)
IsProbablyPrime (based on Miller Rabin Primality Test)
보시다시피, TIntX operator overloading 사용하여 모든 표준 산술 연산자를 구현하므로 일반적인 정수와 함께 작업하는 것과 같이 개발자에게는 사용량이 투명합니다.
내부 TIntX 라이브러리는 FHT (Fast Hartley Transform)를 사용한 곱셈이 수행 될 때 부동 소수점 수로 작동하므로 어느 시점에서 올바르게 작동을 중지하고 정밀도를 잃습니다. 운 좋게도,이 불쾌한 부작용 효과는 정수 크기가 약 2^28 바이트 인 경우 실제로 큰 정수에 대해 나타나기 시작합니다. 어쨌든, 그러한 오류를 포착하기 위해 일부 코드가 추가되었고, FHT 곱셈 결과 유효성이 코드로 확인되었습니다. 각 큰 정수의 마지막 숫자를 사용하고 고전적인 접근 방식을 사용한 다음 클래식 결과의 마지막 n 자리를 FHT 결과의 마지막 n 자리와 비교합니다 (따라서 간단한 CRC 점검). 불일치가 발견되면 EFhtMultiplicationException 이 발생합니다. 이 점검은 글로벌 설정을 사용하여 비활성화 할 수 있습니다.
정말 큰 정수 번호 (위의 Power 1048576의 42와 같은) ToString() 호출은 실행하는 데 시간이 많이 걸릴 수 있습니다. 이는 내부 TIntX 큰 정수가 UInt32 어레이의 2^32 베이스 숫자로 저장되고 10 진수 문자열 출력을 생성하기 위해 2^32 베이스에서 10 진수로 변환해야하기 때문입니다. 이러한 숫자 스토리지 접근 방식은 의도적으로 선택되었습니다. ToString() 느리게 만들지 만 ToString() 를 효율적으로 사용하고 10베이스 스토리지의 전원보다 숫자에 대한 원시 작업을 ToString() 빠르게 만듭니다.
지원되는 컴파일러
FreePascal 3.0.0 and Above.
Delphi 2010 and Above.
라이브러리 설치.
방법 1 :
"패키지"폴더에서 제공된 패키지를 사용하십시오.
방법 2 :
프로젝트 검색 경로에 라이브러리 경로와 하위 경로를 추가하십시오.
단위 테스트.
단위 테스트를 실행하려면
FPC 3.0.0 이상
Simply compile and run "IntXLib.Tests" project in "FreePascal.Tests" Folder.
방법 1 (testinsight 및 dunitx 사용) (선호).
1). Download and Install TestInsight (and DunitX if not available).
2). Open Project Options of Unit Test (IntXLib.Tests.TestInsight) in "Delphi.Tests"
Folder.
3). To Use TestInsight, right-click on the project, then select
"Enable for TestInsight" or "TestInsight Project".
Save Project then Build and Run Test Project through TestInsight.
방법 2 (Dunitx 콘솔 러너 사용).
1). Download and Install DunitX (if not available).
2). Open Project Options of Unit Test (IntXLib.Tests.TestInsight) in "Delphi.Tests"
Folder.
3). Save Project then Build and Run Test Project..
###특허
이 "소프트웨어"는 MIT License (MIT) 에 따라 라이센스가 부여됩니다.
1MhFfW7tDuEHQSgie65uJcAfJgCNchGeKf0x6c1DC21aeC49A822A4f1E3bf07c623C2C1978a98345367-40 Special Thanks to first of all, (Andriy Kozachuk) for creating the
Original CSharp version, members of Delphi Developers Community on Google Plus,
Uncle Midnight,Ron4Fun for various support offered.