source: branches/virt simple/UBigInt.pas

Last change on this file was 88, checked in by chronos, 8 years ago
  • Added: Another implementation of simple virtual machine.
File size: 3.0 KB
Line 
1unit UBigInt;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils;
9
10type
11
12 { TBigInt }
13
14 TBigInt = record
15 Value: array of Byte;
16 class operator Add(A, B: TBigInt): TBigInt;
17 class operator Subtract(A, B: TBigInt): TBigInt;
18 class operator Multiply(A, B: TBigInt): TBigInt;
19 class operator Divide(A, B: TBigInt): TBigInt;
20 class operator IntDivide(A, B: TBigInt): TBigInt;
21 class operator Modulus(A, B: TBigInt): TBigInt;
22 class operator GreaterThan(A: TBigInt; B: TBigInt): Boolean;
23 class operator GreaterThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
24 class operator LessThan(A: TBigInt; B: TBigInt): Boolean;
25 class operator LessThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
26 class operator Implicit(A: Integer): TBigInt;
27 class operator Implicit(A: ShortInt): TBigInt;
28 class operator Implicit(A: Int64): TBigInt;
29 class operator Implicit(A: TBigInt): LongInt;
30 class operator Implicit(A: TBigInt): Int64;
31 class operator Equal(A: TBigInt; B: TBigInt): Boolean;
32 end;
33
34function IntToHex(Value: TBigInt; Digits: Integer): string; overload;
35function IntToStr(Value: TBigInt): string; overload;
36
37implementation
38
39{ TBigInt }
40
41class operator TBigInt.Add(A, B: TBigInt): TBigInt;
42var
43 I: Integer;
44begin
45 for I := 0 to Length(A.Value) - 1 do
46 Result.Value[I] := A.Value[I] + B.Value[I];
47 //Result := ;
48end;
49
50class operator TBigInt.Subtract(A, B: TBigInt): TBigInt;
51begin
52
53end;
54
55class operator TBigInt.Multiply(A, B: TBigInt): TBigInt;
56begin
57
58end;
59
60class operator TBigInt.Divide(A, B: TBigInt): TBigInt;
61begin
62
63end;
64
65class operator TBigInt.IntDivide(A, B: TBigInt): TBigInt;
66begin
67
68end;
69
70class operator TBigInt.Modulus(A, B: TBigInt): TBigInt;
71begin
72
73end;
74
75class operator TBigInt.GreaterThan(A: TBigInt; B: TBigInt): Boolean;
76begin
77
78end;
79
80class operator TBigInt.GreaterThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
81begin
82
83end;
84
85class operator TBigInt.LessThan(A: TBigInt; B: TBigInt): Boolean;
86begin
87
88end;
89
90class operator TBigInt.LessThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
91begin
92
93end;
94
95class operator TBigInt.Implicit(A: Integer): TBigInt;
96begin
97 SetLength(Result.Value, SizeOf(Integer));
98 Move(A, Result.Value[0], SizeOf(Integer));
99end;
100
101class operator TBigInt.Implicit(A: ShortInt): TBigInt;
102begin
103 SetLength(Result.Value, SizeOf(ShortInt));
104 Move(A, Result.Value[0], SizeOf(ShortInt));
105end;
106
107class operator TBigInt.Implicit(A: Int64): TBigInt;
108begin
109 SetLength(Result.Value, SizeOf(Int64));
110 Move(A, Result.Value[0], SizeOf(Int64));
111end;
112
113class operator TBigInt.Implicit(A: TBigInt): LongInt;
114begin
115 Move(A.Value[0], A, SizeOf(LongInt));
116end;
117
118class operator TBigInt.Implicit(A: TBigInt): Int64;
119begin
120 Move(A.Value[0], A, SizeOf(Int64));
121end;
122
123class operator TBigInt.Equal(A: TBigInt; B: TBigInt): Boolean;
124begin
125 Result := (Length(A.Value) = Length(B.Value)) and
126 CompareMem(Addr(A.Value[0]), Addr(A.Value[0]), Length(A.Value));
127end;
128
129function IntToHex(Value: TBigInt; Digits: Integer): string;
130begin
131
132end;
133
134function IntToStr(Value: TBigInt): string;
135begin
136
137end;
138
139end.
140
Note: See TracBrowser for help on using the repository browser.