blob: 88d517e12f3f15b359d58f86bb5aa273e28640e2 (
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
{****************************************************************}
{ CODE GENERATOR TEST PROGRAM }
{****************************************************************}
{ NODE TESTED : secondtypeconvert() -> second_int_to_real }
{****************************************************************}
{ PRE-REQUISITES: secondload() }
{ secondassign() }
{ secondcalln() }
{ secondinline() }
{ secondadd() }
{****************************************************************}
{ DEFINES: }
{****************************************************************}
{ REMARKS: Tests integer to real conversion }
{ This routine assumes that there is a type conversion }
{ from all types to s32bit, u32bit or s64bit before conversion }
{ to a real. }
{****************************************************************}
program tcnvint4;
{$ifdef VER70}
{$define tp}
{$endif}
{$R-}
{$ifdef tp}
type
smallint = integer;
{$endif}
procedure fail;
begin
WriteLn('Failure.');
halt(1);
end;
const
RESULT_U64BIT = qword($8fc0000000000000);
RESULT_S64BIT = -101234;
RESULT_S32BIT = -1000000;
RESULT_U32BIT = 2000000;
RESULT_S16BIT = -12123;
RESULT_U16BIT = 12123;
RESULT_U8BIT = 247;
RESULT_S8BIT = -123;
{$ifndef tp}
function gets64bit : int64;
begin
gets64bit := RESULT_S64BIT;
end;
function getu64bit : qword;
begin
getu64bit := RESULT_U64BIT;
end;
{$endif}
function gets32bit : longint;
begin
gets32bit := RESULT_S32BIT;
end;
function gets16bit : smallint;
begin
gets16bit := RESULT_S16BIT;
end;
function gets8bit : shortint;
begin
gets8bit := RESULT_S8BIT;
end;
function getu8bit : byte;
begin
getu8bit := RESULT_U8BIT;
end;
function getu16bit : word;
begin
getu16bit := RESULT_U16BIT;
end;
function getu32bit : longint;
begin
getu32bit := RESULT_U32BIT;
end;
var
s32bit : longint;
failed : boolean;
s16bit : smallint;
s8bit : shortint;
u8bit : byte;
u16bit : word;
{$ifndef tp}
s64bit : int64;
u32bit : cardinal;
{$endif}
result_val : real;
begin
{ left : LOC_REFERENCE }
Write('second_int_to_real (left : LOC_REFERENCE)...');
s64bit := RESULT_S64BIT;
failed := false;
result_val := s64bit;
if trunc(result_val) <> RESULT_S64BIT then
failed:=true;
s32bit := RESULT_S32BIT;
result_val := s32bit;
if trunc(result_val) <> RESULT_S32BIT then
failed:=true;
u32bit := high(u32bit);
result_val := u32bit;
if trunc(result_val) <> high(u32bit) then
failed:=true;
u32bit := RESULT_U32BIT;
result_val := u32bit;
if trunc(result_val) <> RESULT_U32BIT then
failed:=true;
s16bit := RESULT_S16BIT;
result_val := s16bit;
if trunc(result_val) <> RESULT_S16BIT then
failed:=true;
u16bit := RESULT_U16BIT;
result_val := u16bit;
if trunc(result_val) <> RESULT_U16BIT then
failed:=true;
s8bit := RESULT_S8BIT;
result_val := s8bit;
if trunc(result_val) <> RESULT_S8BIT then
failed:=true;
u8bit := RESULT_U8BIT;
result_val := u8bit;
if trunc(result_val) <> RESULT_U8BIT then
failed:=true;
if failed then
fail
else
WriteLn('Passed!');
Write('second_int_to_real (left : LOC_REGISTER)...');
failed := false;
result_val := gets64bit;
if trunc(result_val) <> RESULT_S64BIT then
failed:=true;
result_val := getu64bit;
if result_val <> 10358279142952140800.0 then
begin
writeln('got ',result_val:0);
writeln('expected ',10358279142952140800.0);
failed:=true;
end;
result_val := gets32bit;
if trunc(result_val) <> RESULT_S32BIT then
failed:=true;
result_val := getu32bit;
if trunc(result_val) <> RESULT_U32BIT then
failed:=true;
result_val := getu8bit;
if trunc(result_val) <> RESULT_u8BIT then
failed:=true;
result_val := gets8bit;
if trunc(result_val) <> RESULT_s8BIT then
failed:=true;
result_val := gets16bit;
if trunc(result_val) <> RESULT_S16BIT then
failed:=true;
result_val := getu16bit;
if trunc(result_val) <> RESULT_U16BIT then
failed:=true;
if failed then
fail
else
WriteLn('Passed!');
end.
|