blob: 79cd719518b079a7d6338f47474e860af3b3b786 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
{ Source provided for Free Pascal Bug Report 2109 }
{ Submitted by "Layton Davis" on 2002-09-05 }
{ e-mail: layton@brandom.com }
unit tw2109;
{$mode fpc}
interface
{ warning!!! -- pascal re-generates every result in an operator statement }
{ attributes of the results have to be carried forward from the old value }
{ as a work arround we have to ask the user to assign the original destination variable to OldBCD }
{ or OldZoned before doing any assignments or arithmetic }
{ fixme!!! -- assignment statements are used automatically to provide data }
{ type conversion. I need to provide a safety net so that this doesn't create bad behavior }
{ from this library }
type
flint = record
data : longint;
dec : byte;
end;
bcddata = array[1..18] of char;
bcd = record
data : ^bcddata;
bcdlen : byte;
bcddec : byte;
end;
zoneddata = array[1..9] of char;
zoned = record
data : ^zoneddata;
zonelen : byte;
zonedec : byte;
end;
operator := (a:bcd) b:Integer;
operator := (a:bcd) b:Longint;
operator := (a:bcd) b:FLInt;
function initbcd(blen, bdec:byte; bcdptr:pointer):bcd;
operator := (a:integer) b:bcd;
operator := (a:longint) b:bcd;
operator := (a:FLInt) b:bcd;
function initzoned(zlen, zdec:byte; zptr:pointer):zoned;
var
OldBCD : bcd;
implementation
operator := (a:bcd) b:Integer;
var
knt : integer;
begin
b := 0;
for knt := 1 to a.bcdlen - a.bcddec do
begin
b := b * 10;
b := b + ord(a.data^[knt]) - ord('0');
end;
end;
operator := (a:bcd) b: LongInt;
var
test : FLInt;
knt : byte;
begin
test := a;
b := test.data;
knt := test.dec;
while knt > 0 do
begin
b := b div 10;
knt := knt - 1;
end;
end;
operator := (a:bcd) b:FLInt;
var
knt : byte;
begin
b.data := 0;
for knt := 1 to a.bcdlen do
b.data := (b.data * 10) + ord(a.data^[knt]) - ord('0');
b.dec := a.bcddec;
end;
operator := (a:FLInt) b:bcd;
var
tmp : FLInt;
knt : byte;
tmpl : longint;
begin
b := oldbcd;
tmp := a;
while tmp.dec < b.bcddec do
begin
tmp.data := tmp.data * 10;
tmp.dec := tmp.dec + 1;
end;
while tmp.dec > b.bcddec do
begin
tmp.data := tmp.data div 10;
tmp.dec := tmp.dec - 1;
end;
for knt := 1 to b.bcdlen do
b.data^[knt] := '0';
knt := b.bcdlen;
while (knt > 0) and (tmp.data > 0) do
begin
tmpl := tmp.data div 10;
tmpl := tmp.data - (tmpl * 10);
b.data^[knt] := char(ord('0') + tmpl);
tmp.data := tmp.data div 10;
knt := knt - 1;
end;
end;
function initbcd(blen, bdec:byte; bcdptr:pointer):bcd;
var
temp : bcd;
knt : integer;
begin
if bcdptr <> NIL then
temp.data := bcdptr
else
new(temp.data);
temp.bcdlen := blen;
temp.bcddec := bdec;
for knt := 1 to blen do {only fill out the space allocated to us -- as we may be part of a data structure}
temp.data^[knt] := '0';
initbcd := temp;
end;
operator := (a:integer) b:bcd;
var
knt : integer;
temp : integer;
temp2 : integer;
begin
b := oldbcd;
for knt := 1 to b.bcdlen do
b.data^[knt] := '0';
knt := b.bcdlen-b.bcddec;
temp := a;
while (knt > 0 ) and (temp > 0) do
begin
temp2 := temp div 10;
temp2 := temp - (temp2 * 10);
temp := temp div 10;
b.data^[knt] := char(ord('0') + temp2);
knt := knt - 1;
end;
end;
operator := (a:longint) b:bcd;
var
knt : integer;
temp : longint;
temp2 : longint;
begin
b := oldbcd;
for knt := 1 to b.bcdlen do
b.data^[knt] := '0';
knt := b.bcdlen-b.bcddec;
temp := a;
while (knt > 0 ) and (temp > 0) do
begin
temp2 := temp div 10;
temp2 := temp - (temp2 * 10);
temp := temp div 10;
b.data^[knt] := char(ord('0') + temp2);
knt := knt - 1;
end;
end;
function initzoned(zlen, zdec:byte; zptr:pointer):zoned;
begin
end;
end.
|