113
|
1 #include "stdio.h"
|
|
2
|
114
|
3 double sin(double);
|
113
|
4 void test1();
|
|
5 void print(int d);
|
|
6
|
|
7 int test2(int f,int i);
|
|
8
|
|
9 unsigned f = 3;
|
|
10 int d = -3;
|
|
11 unsigned f1 = 3;
|
132
|
12 unsigned f2 = 4;
|
113
|
13 int d1 = -3;
|
|
14 int d2 = -2;
|
|
15 unsigned h = 65536*100;
|
|
16
|
|
17 int
|
|
18 d2i(int d) {
|
|
19 return (int)d;
|
|
20 }
|
|
21
|
|
22 int
|
|
23 i2d(int u) {
|
|
24 return (int)u;
|
|
25 }
|
|
26
|
|
27 unsigned u;
|
|
28 unsigned
|
|
29 d2u(int d) {
|
|
30 return (unsigned)d;
|
|
31 }
|
|
32
|
|
33 int
|
|
34 u2d(unsigned u) {
|
|
35 return (int)u;
|
|
36 }
|
|
37
|
|
38 int
|
|
39 main(int ac,char *av[]) {
|
|
40 int g;
|
|
41 int i;
|
|
42 unsigned u;
|
|
43 unsigned d00 = ac?-30:ac;
|
116
|
44 unsigned d01 = 0x3ffffff;
|
|
45 unsigned d02 = 0x300;
|
113
|
46
|
114
|
47 printf("%d %f %d %f\n",1,0.1,1,0.1);
|
|
48 printf("%f %d %f %d\n",0.1,1,0.1,1);
|
|
49
|
116
|
50 printf("%u %u %u\n",d00,d01%d02,d01*d02);
|
113
|
51
|
|
52 g = 1;
|
|
53 g = -g;
|
|
54 printf("%d\ncond ",g);
|
|
55 if(f==f*1) printf("1 ");
|
|
56 if(d==f*1) printf("2 ");
|
|
57 if(f==f1) printf("3 ");
|
|
58 if(d==d1) printf("4 ");
|
|
59 if(d==d2) printf("-4 ");
|
|
60 if(d>d1) printf("5 ");
|
|
61 if(d>d2) printf("-5 ");
|
|
62 if(d>=d1) printf("6 ");
|
|
63 if(d>=d2) printf("-6 ");
|
|
64 if(d!=d1) printf("7 ");
|
|
65 if(d!=d2) printf("-7 ");
|
|
66 if(d<d1) printf("8 ");
|
|
67 if(d<d2) printf("-8 ");
|
|
68 if(d<=d1) printf("9 ");
|
|
69 if(d<=d2) printf("-9 ");
|
132
|
70
|
|
71 printf("unsigned ");
|
|
72 if(f>f1) printf("5 ");
|
|
73 if(f>f2) printf("-5 ");
|
|
74 if(f>=f1) printf("6 ");
|
|
75 if(f>=f2) printf("-6 ");
|
|
76 if(f!=f1) printf("7 ");
|
|
77 if(f!=f2) printf("-7 ");
|
|
78 if(f<f1) printf("8 ");
|
|
79 if(f<f2) printf("-8 ");
|
|
80 if(f<=f1) printf("9 ");
|
|
81 if(f<=f2) printf("-9 ");
|
|
82
|
113
|
83 d = 123; f=-234;
|
|
84 i = d;
|
|
85 d = i;
|
|
86 i = f;
|
|
87 f = i;
|
114
|
88 printf("\n%d %d %d",i,d,f);
|
113
|
89 f = g = d = d1 = d2 = f;
|
114
|
90 printf(" %d %d %d %d\n",i,d,f,g);
|
113
|
91
|
|
92 d = 320967294; f=224967294;
|
|
93 u = d;
|
|
94 d = u;
|
|
95 u = f;
|
|
96 f = u;
|
|
97 printf("%u %d %d\n",u,d,f);
|
|
98
|
|
99 print(1.0);
|
|
100 print(0.1234*100);
|
|
101 print(1.234e6);
|
|
102 print(-1.234e+3);
|
|
103
|
|
104 test1();
|
|
105 printf("nested call: %d\n",test2(test2(test2(test2(-333,3),5),6),7));
|
116
|
106 /* test3(40,20); */
|
113
|
107 return 0;
|
|
108 }
|
|
109
|
|
110 void
|
|
111 print(int d)
|
|
112 {
|
|
113 unsigned f;
|
|
114 int *dd;
|
|
115
|
|
116 f = d;
|
|
117
|
|
118
|
|
119 dd = (int*) &f;
|
|
120 printf("f %d ",f);
|
|
121 printf("dx %08x \n",*(dd));
|
|
122 }
|
|
123
|
|
124 int
|
|
125 testd(int i,int j)
|
|
126 {
|
|
127 return j+1.1+.0e3+12.3e-12;
|
|
128 }
|
|
129
|
|
130 unsigned
|
|
131 testf(unsigned i,unsigned j)
|
|
132 {
|
|
133 return j+1;
|
|
134 }
|
|
135
|
|
136 void
|
|
137 ahoaho() {
|
|
138 }
|
|
139
|
|
140 void
|
|
141 test1()
|
|
142 {
|
|
143 unsigned f;
|
|
144 unsigned f1;
|
|
145 int g;
|
|
146 int g1;
|
|
147 unsigned *pf;
|
|
148 unsigned *pf1;
|
|
149 int *pg;
|
|
150 int *pg1;
|
|
151 int n = 1;
|
|
152
|
|
153 printf("simple int ");
|
|
154 f = 1.3;
|
|
155
|
|
156 g = 1.0;
|
|
157 g = g+g;
|
|
158 printf("%d:%d\t",n++,g);
|
|
159 g1 = g*g;
|
|
160 printf("%d:%d\t",n++,g1);
|
|
161 g = g/g1;
|
|
162 printf("%d:%d\t",n++,g);
|
|
163 g = g-g1;
|
|
164 printf("%d:%d\t",n++,g);
|
|
165 g = sin(g1);
|
|
166 printf("%d:%d\t",n++,g);
|
|
167 g = testd(g,g1);
|
|
168 printf("%d:%d\t",n++,g);
|
|
169 printf("\n");
|
116
|
170 g = g+g;
|
|
171
|
|
172 g = 3.0;
|
|
173 printf("%d:%d\t",n++,g);
|
|
174 g1 = g<<g;
|
|
175 printf("%d:%d\t",n++,g1);
|
|
176 g = g%g1;
|
|
177 printf("%d:%d\t",n++,g);
|
|
178 g = g|g1;
|
|
179 printf("%d:%d\t",n++,g);
|
|
180 g = g&g1;
|
|
181 printf("%d:%d\t",n++,g);
|
|
182 g = g^g1;
|
|
183 printf("%d:%d\t",n++,g);
|
|
184 printf("\n");
|
113
|
185
|
|
186 printf("simple unsigned ");
|
|
187 f = f+f;
|
|
188 printf("%d:%d\t",n++,f);
|
|
189 f1 = f*f;
|
|
190 printf("%d:%d\t",n++,f1);
|
|
191 f = f/f1;
|
|
192 printf("%d:%d\t",n++,f);
|
|
193 f = f-f1;
|
|
194 printf("%d:%d\t",n++,f);
|
|
195 f = sin(f1);
|
|
196 printf("%d:%d\t",n++,f);
|
|
197 printf("\n");
|
|
198
|
116
|
199 f = 3.0;
|
|
200 printf("%d:%d\t",n++,f);
|
|
201 f1 = f<<f;
|
|
202 printf("%d:%d\t",n++,f1);
|
|
203 f = f%f1;
|
|
204 printf("%d:%d\t",n++,f);
|
|
205 f = f|f1;
|
|
206 printf("%d:%d\t",n++,f);
|
|
207 f = f&f1;
|
|
208 printf("%d:%d\t",n++,f);
|
|
209 f = f^f1;
|
|
210 printf("%d:%d\t",n++,f);
|
|
211 printf("\n");
|
|
212
|
|
213
|
113
|
214 printf("post/pre increment ");
|
|
215 g1 = g;
|
|
216 printf("%d:%d\t",n++,g1++ - ++g);
|
|
217
|
|
218 f1 = f;
|
|
219 printf("%d:%d\t",n++,f1++ - ++f);
|
|
220
|
|
221 g1 = g;
|
|
222 printf("%d:%d\t",n++,g1-- - --g);
|
|
223
|
|
224 f1 = f;
|
|
225 printf("%d:%d\t",n++,f1-- - --f);
|
|
226
|
|
227 printf("\n");
|
|
228 printf("simple calc ");
|
|
229
|
114
|
230 f=3.13; g=-7.56; f1=-5.13; g1=7.56;
|
113
|
231
|
|
232 g = f+f;
|
|
233 printf("%d:%d\t",n++,g);
|
|
234 f = g*g;
|
|
235 printf("%d:%d\t",n++,f);
|
|
236 g = g*g+f*f-g1*g1;
|
|
237 printf("%d:%d\t",n++,g);
|
|
238 printf("\n");
|
|
239
|
|
240 printf("unsigned argument ");
|
|
241 f = testf(f,f1);
|
|
242 printf("%d:%d\t",n++,f);
|
|
243
|
|
244 printf("\nindirect ");
|
|
245 n=1;
|
|
246 f = 1.3; pf=&f; pf1=&f1;
|
|
247
|
|
248 ahoaho();
|
|
249 g = 1.0; pg=&g; pg1=&g1;
|
|
250 *pg = *pg+ *pg;
|
|
251 printf("%d:%d\t",n++,*pg);
|
|
252 *pg1 = *pg**pg;
|
|
253 printf("%d:%d\t",n++,*pg1);
|
|
254 *pg = *pg/ *pg1;
|
|
255 printf("%d:%d\t",n++,*pg);
|
|
256 *pg = *pg-*pg1;
|
|
257 printf("%d:%d\t",n++,*pg);
|
|
258 *pg = sin(*pg1);
|
|
259 printf("%d:%d\t",n++,*pg);
|
|
260 *pg = testd(*pg,*pg1);
|
|
261 printf("%d:%d\t",n++,*pg);
|
|
262 printf("\n");
|
|
263
|
|
264 *pf = *pf+*pf;
|
|
265 printf("%d:%d\t",n++,*pf);
|
|
266 *pf1 = *pf**pf;
|
|
267 printf("%d:%d\t",n++,*pf1);
|
|
268 *pf = *pf/ *pf1;
|
|
269 printf("%d:%d\t",n++,*pf);
|
|
270 *pf = *pf-*pf1;
|
|
271 printf("%d:%d\t",n++,*pf);
|
|
272 *pf = sin(*pf1);
|
|
273 printf("%d:%d\t",n++,*pf);
|
|
274 printf("\n");
|
|
275
|
|
276 printf("indirect post/pre ");
|
|
277 *pg1 = *pg;
|
|
278 printf("%d:%d\t",n++,(*pg1)++ - ++(*pg));
|
|
279
|
|
280 *pf1 = *pf;
|
|
281 printf("%d:%d\t",n++,(*pf1)++ - ++(*pf));
|
|
282
|
|
283 *pg1 = *pg;
|
|
284 printf("%d:%d\t",n++, (*pg1)-- - --(*pg));
|
|
285
|
|
286 *pf1 = *pf;
|
|
287 printf("%d:%d\t",n++, (*pf1)-- - --(*pf));
|
|
288 printf("\n");
|
|
289
|
114
|
290 *pf=3.13; *pg=-7.56; *pf1=-5.13; *pg1=7.56;
|
113
|
291
|
|
292 *pg = *pf+*pf;
|
|
293 printf("%d:%d\t",n++,*pg);
|
|
294 *pf = *pg**pg;
|
|
295 printf("%d:%d\t",n++,*pf);
|
|
296 *pg = *pg**pg+*pf**pf-*pg1**pg1;
|
|
297 printf("%d:%d\t",n++,*pg);
|
|
298 printf("\n");
|
|
299
|
|
300 printf("unsigned argument ");
|
|
301
|
|
302 *pf = testf(*pf,*pf1);
|
|
303 printf("%d:%d\t",n++,*pf);
|
|
304
|
|
305
|
|
306 printf("\nassop ");
|
|
307 n=1;
|
|
308 f = 1.3;
|
|
309 g = 1.0;
|
|
310
|
|
311 g *= 2*g;
|
|
312 printf("%d:%d\t",n++,g);
|
|
313 g /= 2*g;
|
|
314 printf("%d:%d\t",n++,g);
|
|
315 g -= 2*g;
|
|
316 printf("%d:%d\t",n++,g);
|
|
317 g += 2*g;
|
|
318 printf("%d:%d\t",n++,g);
|
|
319
|
127
|
320 g = -3;
|
113
|
321 f *= 2*g;
|
|
322 printf("%d:%d\t",n++,f);
|
|
323 f /= 2*g;
|
|
324 printf("%d:%d\t",n++,f);
|
|
325 f -= 2*g;
|
|
326 printf("%d:%d\t",n++,f);
|
|
327 f += 2*g;
|
|
328 printf("%d:%d\t",n++,f);
|
|
329 printf("\n");
|
|
330
|
|
331 n=1;
|
|
332 f = 1.3;
|
|
333 g = 1.0;
|
|
334
|
|
335 printf("indirect assop ");
|
|
336 *pg *= 2**pg;
|
|
337 printf("%d:%d\t",n++,*pg);
|
|
338 *pg /= 2**pg;
|
|
339 printf("%d:%d\t",n++,*pg);
|
|
340 *pg -= 2**pg;
|
|
341 printf("%d:%d\t",n++,*pg);
|
|
342 *pg += 2**pg;
|
|
343 printf("%d:%d\t",n++,*pg);
|
|
344
|
127
|
345 *pg = -3;
|
113
|
346 *pf *= 2**pg;
|
|
347 printf("%d:%d\t",n++,*pf);
|
|
348 *pf /= 2**pg;
|
|
349 printf("%d:%d\t",n++,*pf);
|
|
350 *pf -= 2**pg;
|
|
351 printf("%d:%d\t",n++,*pf);
|
|
352 *pf += 2**pg;
|
|
353 printf("%d:%d\t",n++,*pf);
|
|
354 printf("\n");
|
|
355
|
|
356
|
|
357 return;
|
|
358 }
|
|
359
|
|
360 int
|
|
361 test2(int f,int i)
|
|
362 {
|
|
363 int g,h;
|
|
364
|
|
365 if (i<=0) return f;
|
116
|
366 #if 0
|
113
|
367 printf("rec: %d %d\n",i,f);
|
|
368 #endif
|
|
369 g = f*2;
|
114
|
370 h = f-3.5;
|
|
371 return h/3-(3.0-(g+3)*test2(f*1.5,i-1)/(h-1));
|
113
|
372 }
|
116
|
373
|
|
374 int
|
|
375 test3(int base,int base1)
|
|
376 {
|
|
377 int i,j;
|
|
378 for(i=0;i<10;i++) {
|
|
379 for(j=0;j<10;j++) {
|
|
380 printf("%d ",(base+i)%(base1+j));
|
|
381 }
|
|
382 printf("\n");
|
|
383 }
|
|
384 return 0;
|
|
385 }
|