Skip to content

Commit 7b03882

Browse files
committed
Initial Commit
Time to Celebrate the Success
1 parent 7b598cc commit 7b03882

31 files changed

+22596
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
# Delphi compiler-generated binaries (safe to delete)
3030
*.exe
31-
*.dll
3231
*.bpl
3332
*.bpi
3433
*.dcp
@@ -67,3 +66,6 @@ __recovery/
6766

6867
# Boss dependency manager vendor folder https://github.com/HashLoad/boss
6968
modules/
69+
70+
#MacOS
71+
.DS_Store

CompilerAndRTLVersions.pas

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
unit CompilerAndRTLVersions;
2+
3+
// See https://blog.dummzeuch.de/2018/12/02/conditional-compilation-for-various-delphi-versions/
4+
// Slightly modified
5+
6+
interface
7+
8+
const
9+
10+
// Compiler versions
11+
12+
CompilerVersionDelphi6 = 14.0;
13+
CompilerVersionDelphi7 = 15.0;
14+
CompilerVersionDelphi71 = 15.0;
15+
CompilerVersionDelphi8 = 16.0;
16+
17+
CompilerVersionDelphi2005 = 17.0;
18+
CompilerVersionDelphi2006 = 18.0;
19+
CompilerVersionDelphi2007 = 18.5;
20+
CompilerVersionDelphi2007NET = 19.0;
21+
CompilerVersionDelphi2009 = 20.0;
22+
CompilerVersionDelphi2010 = 21.0;
23+
24+
CompilerVersionDelphiXE = 22.0;
25+
CompilerVersionDelphiXE2 = 23.0;
26+
CompilerVersionDelphiXE3 = 24.0;
27+
CompilerVersionDelphiXE4 = 25.0;
28+
CompilerVersionDelphiXE5 = 26.0;
29+
ComplierVersionAppMethod1 = 26.5;
30+
CompilerVersionDelphiXE6 = 27.0;
31+
CompilerVersionDelphiXE7 = 28.0;
32+
CompilerVersionDelphiXE8 = 29.0;
33+
34+
CompilerVersionDelphi10 = 30.0;
35+
CompilerVersionDelphi100 = 30.0;
36+
CompilerVersionDelphiSeattle = 30.0;
37+
CompilerVersionDelphi101 = 31.0;
38+
CompilerVersionDelphiBerlin = 31.0;
39+
CompilerVersionDelphi102 = 32.0;
40+
CompilerVersionDelphiTokyo = 32.0;
41+
CompilerVersionDelphi103 = 33.0;
42+
CompilerVersionDelphiRio = 33.0;
43+
44+
// RTL versions
45+
46+
RTLVersionDelphi6 = 14.0;
47+
RTLVersionDelphi7 = 15.0;
48+
RTLVersionDelphi71 = 15.0;
49+
RTLVersionDelphi8 = 16.0;
50+
51+
RTLVersionDelphi2005 = 17.0;
52+
RTLVersionDelphi2006 = 18.0;
53+
RTLVersionDelphi2007 = 18.5;
54+
RTLVersionDelphi2007NET = 19.0;
55+
RTLVersionDelphi2009 = 20.0;
56+
RTLVersionDelphi2010 = 21.0;
57+
58+
RTLVersionDelphiXE = 22.0;
59+
RTLVersionDelphiXE2 = 23.0;
60+
RTLVersionDelphiXE3 = 24.0;
61+
RTLVersionDelphiXE4 = 25.0;
62+
RTLVersionDelphiXE5 = 26.0;
63+
RTLVersionAppMethod1 = 26.5;
64+
RTLVersionDelphiXE6 = 27.0;
65+
RTLVersionDelphiXE7 = 28.0;
66+
RTLVersionDelphiXE8 = 29.0;
67+
68+
RTLVersionDelphi10 = 30.0;
69+
RTLVersionDelphi100 = 30.0;
70+
RTLVersionDelphiSeattle = 30.0;
71+
RTLVersionDelphi101 = 31.0;
72+
RTLVersionDelphiBerlin = 31.0;
73+
RTLVersionDelphi102 = 32.0;
74+
RTLVersionDelphiTokyo = 32.0;
75+
RTLVersionDelphi103 = 33.0;
76+
RTLVersionDelphiRio = 33.0;
77+
78+
implementation
79+
80+
end.

GenerateBaseConversionTables.dpr

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
program GenerateBaseConversionTables;
2+
3+
{$APPTYPE CONSOLE}
4+
5+
{$R *.res}
6+
7+
uses
8+
System.SysUtils, System.Math, System.Classes;
9+
10+
type
11+
TBaseInfo = record
12+
MaxPower: UInt64;
13+
MaxDigits: Integer;
14+
PowerOfTwo: Boolean;
15+
MaxFactor: UInt32;
16+
end;
17+
18+
var
19+
BaseInfos32: array[2..36] of TBaseInfo;
20+
BaseInfos64: array[2..36] of TBaseInfo;
21+
22+
MaxFactorShift: Integer;
23+
24+
function IsPowerofTwo(I: Integer): Boolean;
25+
begin
26+
Result := (I and (I - 1)) = 0;
27+
end;
28+
29+
procedure FindMaxValue(const Base, Max: UInt64; var Info: TBaseInfo);
30+
var
31+
MaxPower: UInt64;
32+
begin
33+
if (Base < 2) or (Base > 36) then
34+
raise EInvalidArgument.Create('Invalid base value');
35+
MaxPower := Max div Base;
36+
Write('Max = ', MaxPower, ': ');
37+
Info.PowerOfTwo := IsPowerofTwo(Base);
38+
Info.MaxPower := Base;
39+
Info.MaxDigits := 1;
40+
repeat
41+
Write(Info.MaxPower, ' ');
42+
Info.MaxPower := Info.MaxPower * Base;
43+
Inc(Info.MaxDigits);
44+
until Info.MaxPower >= MaxPower;
45+
Writeln(Info.MaxPower);
46+
Info.MaxFactor := Round((Ln(2) / Ln(Info.MaxPower)) * (1 shl MaxFactorShift));
47+
Writeln;
48+
end;
49+
50+
const
51+
Bools: array[Boolean] of string = ('False', 'True');
52+
53+
procedure WriteArray(W: TStreamWriter; const Name: string; const Bases: array of TBaseInfo; const Comment: string);
54+
var
55+
Comma: Char;
56+
I: Integer;
57+
begin
58+
Comma := ',';
59+
W.WriteLine(' // %s', [Comment]);
60+
W.WriteLine(' %s: array[TNumberBase] of BigInteger.TNumberBaseInfo = ', [Name]);
61+
W.WriteLine(' (');
62+
63+
for I := Low(Bases) to High(Bases) do
64+
begin
65+
if I = High(Bases) then
66+
Comma := ' ';
67+
W.WriteLine(Format(' (MaxPower: %20u; MaxDigits: %2d; PowerofTwo: %5s; MaxFactor: %6u)%s // Base %d',
68+
[Bases[I].MaxPower, Bases[I].MaxDigits, Bools[Bases[I].PowerOfTwo], Bases[I].MaxFactor, Comma, I + 2],
69+
TFormatSettings.Invariant));
70+
end;
71+
72+
W.WriteLine(' );');
73+
end;
74+
75+
procedure WriteArrays;
76+
var
77+
W: TStreamWriter;
78+
begin
79+
W := TStreamWriter.Create('bases.inc', False, TEncoding.UTF8);
80+
try
81+
W.WriteLine('{$IF CompilerVersion < 29.0}');
82+
W.WriteLine(' {$IF (DEFINED(WIN32) or DEFINED(CPUX86)) AND NOT DEFINED(CPU32BITS)}');
83+
W.WriteLine(' {$DEFINE CPU32BITS}');
84+
W.WriteLine(' {$IFEND}');
85+
W.WriteLine(' {$IF (DEFINED(WIN64) OR DEFINED(CPUX64)) AND NOT DEFINED(CPU64BITS)}');
86+
W.WriteLine(' {$DEFINE CPU64BITS}');
87+
W.WriteLine(' {$IFEND}');
88+
W.WriteLine('{$IFEND}');
89+
W.WriteLine;
90+
W.WriteLine('const');
91+
W.WriteLine(' CMaxFactorShift = %d;', [MaxFactorShift]);
92+
93+
W.WriteLine('{$IFDEF CPU64BITS}');
94+
WriteArray(W, 'CBaseInfos', BaseInfos64, 'Maximum powers of given bases that fit into UInt64');
95+
W.WriteLine('{$ELSE}');
96+
WriteArray(W, 'CBaseInfos', BaseInfos32, 'Maximum powers of given bases that fit into UInt32');
97+
W.WriteLine('{$ENDIF}');
98+
W.WriteLine;
99+
finally
100+
W.Free;
101+
end;
102+
end;
103+
104+
var
105+
I: Integer;
106+
107+
begin
108+
try
109+
MaxFactorShift := 24;
110+
for I := 2 to 36 do
111+
begin
112+
FindMaxValue(I, High(UInt32), BaseInfos32[I]);
113+
FindMaxValue(I, High(UInt64), BaseInfos64[I]);
114+
end;
115+
WriteArrays;
116+
except
117+
on E: Exception do
118+
Writeln(E.ClassName, ': ', E.Message);
119+
end;
120+
Readln;
121+
end.
122+

0 commit comments

Comments
 (0)