79
|
1 #include "stdio.h"
|
|
2
|
|
3 void test1();
|
82
|
4 void print(double d);
|
79
|
5
|
81
|
6 extern double sin(double);
|
84
|
7 // extern float fsin(float);
|
94
|
8 double test2(double f,int i);
|
81
|
9
|
82
|
10 float f = 0.3;
|
|
11 double d = 0.3;
|
|
12 float f1 = 0.3;
|
|
13 double d1 = 0.3;
|
84
|
14 double d2 = -0.2;
|
96
|
15 float h = 1.0;
|
82
|
16
|
91
|
17 int
|
|
18 d2i(double d) {
|
|
19 return (int)d;
|
|
20 }
|
|
21
|
|
22 double
|
|
23 i2d(int u) {
|
|
24 return (double)u;
|
|
25 }
|
90
|
26
|
91
|
27 unsigned u;
|
|
28 unsigned
|
|
29 d2u(double d) {
|
|
30 return (unsigned)d;
|
|
31 }
|
|
32
|
|
33 double
|
|
34 u2d(unsigned u) {
|
|
35 return (double)u;
|
90
|
36 }
|
|
37
|
379
|
38 double
|
|
39 f2d(float u) {
|
|
40 double u1;
|
|
41 u1 = f1;
|
|
42 return (double)u;
|
|
43 }
|
|
44
|
|
45 float
|
|
46 d2f(double u) {
|
|
47 float u1;
|
|
48 u1 = d1;
|
|
49 return (float)u;
|
|
50 }
|
|
51
|
79
|
52 int
|
|
53 main(int ac,char *av[]) {
|
82
|
54 double g;
|
|
55 int i;
|
85
|
56 unsigned u;
|
108
|
57 double d00 = ac?0.5:3;
|
|
58
|
427
|
59 printf("#0058:%g\n",d00);
|
82
|
60
|
|
61 g = 1.0;
|
|
62 g = -g;
|
427
|
63 printf("#0062:%d\ncond0 ",1);
|
|
64 if(f==f*1.0) printf("#0063:t ");
|
|
65 printf("#0064:%d\ncond1 ",f==f*1.0);
|
|
66 if(d==f*1.0) printf("#0065:t ");
|
|
67 printf("#0066:%d\ncond2 ",d==f*1.0);
|
|
68 if(f==f1) printf("#0067:t ");
|
|
69 printf("#0068:%d\ncond3 ",f==f1);
|
|
70 if(d==d1) printf("#0069:t ");
|
|
71 printf("#0070:%d\ncond4 ",d==d2);
|
|
72 if(d==d2) printf("#0071:t ");
|
|
73 printf("#0072:%d\ncond5 ",(d==d2));
|
|
74 if(d>d1) printf("#0073:t ");
|
|
75 printf("#0074:%d\ncond6 ",d>d1);
|
|
76 if(d>d2) printf("#0075:t ");
|
|
77 printf("#0076:%d\ncond7 ",d>d2);
|
|
78 if(d>=d1) printf("#0077:t ");
|
|
79 printf("#0078:%d\ncond8 ",d>=d1);
|
|
80 if(d>=d2) printf("#0079:t ");
|
|
81 printf("#0080:%d\ncond9 ",d>=d2);
|
|
82 if(d!=d1) printf("#0081:t ");
|
|
83 printf("#0082:%d\ncond10 ",d!=d1);
|
|
84 if(d!=d2) printf("#0083:5 ");
|
|
85 printf("#0084:%d\ncond11 ",d!=d2);
|
|
86 if(d<d1) printf("#0085:t ");
|
|
87 printf("#0086:%d\ncond12 ",d<d1);
|
|
88 if(d<d2) printf("#0087:t ");
|
|
89 printf("#0088:%d\ncond13 ",d<d2);
|
|
90 if(d<=d1) printf("#0089:t ");
|
|
91 printf("#0090:%d\ncond14 ",d<=d1);
|
|
92 if(d<=d2) printf("#0091:t ");
|
|
93 printf("#0092:%d\ncond15 ",d<=d2);
|
85
|
94 d = 123.4234; f=-234.333;
|
82
|
95 i = d;
|
|
96 d = i;
|
|
97 i = f;
|
|
98 f = i;
|
427
|
99 printf("#0098:\ni=%d d=%g f=%f",i,d,f);
|
94
|
100 f = g = d = d1 = d2 = f;
|
427
|
101 printf("#0100: i=%d d=%g f=%f g=%g\n",i,d,f,g);
|
82
|
102
|
86
|
103 d = 4204967294.4234; f=4204967294.4234;
|
85
|
104 u = d;
|
427
|
105 printf("#0104:1: u=%u d=%g f=%f\n",u,d,f);
|
85
|
106 d = u;
|
427
|
107 printf("#0106:2: u=%u d=%g f=%f\n",u,d,f);
|
85
|
108 u = f;
|
427
|
109 printf("#0108:3: u=%u d=%g f=%f\n",u,d,f);
|
85
|
110 f = u;
|
427
|
111 printf("#0110:4: u=%u d=%g f=%f\n",u,d,f);
|
85
|
112
|
82
|
113 print(1.0);
|
|
114 print(0.1234);
|
|
115 print(1.234e10);
|
|
116 print(1.234e-10);
|
|
117
|
79
|
118 test1();
|
427
|
119 printf("#0118:nested call: %g\n",test2(test2(test2(test2(-0.333,3),5),6),7));
|
79
|
120 return 0;
|
|
121 }
|
|
122
|
82
|
123 void
|
|
124 print(double d)
|
|
125 {
|
|
126 float f;
|
|
127 int *dd;
|
|
128
|
|
129 f = d;
|
|
130
|
|
131 dd = (int*) &d;
|
427
|
132 printf("#0131:d %g ",d);
|
|
133 printf("#0132:dx %08x %08x\n",*(dd),*(dd+1));
|
82
|
134
|
|
135 dd = (int*) &f;
|
427
|
136 printf("#0135:f %g ",f);
|
|
137 printf("#0136:dx %08x \n",*(dd));
|
82
|
138 }
|
|
139
|
81
|
140 double
|
|
141 testd(double i,double j)
|
|
142 {
|
87
|
143 return j+1.1+.0e3+12.3e-12;
|
81
|
144 }
|
|
145
|
|
146 float
|
|
147 testf(float i,float j)
|
|
148 {
|
87
|
149 return j+1;
|
81
|
150 }
|
|
151
|
79
|
152 void
|
|
153 test1()
|
|
154 {
|
|
155 float f;
|
|
156 float f1;
|
|
157 double g;
|
|
158 double g1;
|
85
|
159 float *pf;
|
|
160 float *pf1;
|
|
161 double *pg;
|
|
162 double *pg1;
|
|
163 int n = 1;
|
79
|
164
|
427
|
165 printf("#0164:simple double ");
|
79
|
166 f = 1.3;
|
|
167
|
|
168 g = 1.0;
|
|
169 g = g+g;
|
427
|
170 printf("#0169:%d:%g\t",n++,g);
|
79
|
171 g1 = g*g;
|
427
|
172 printf("#0171:%d:%g\t",n++,g1);
|
79
|
173 g = g/g1;
|
427
|
174 printf("#0173:%d:%g\t",n++,g);
|
79
|
175 g = g-g1;
|
427
|
176 printf("#0175:%d:%g\t",n++,g);
|
79
|
177 g = sin(g1);
|
427
|
178 printf("#0177:%d:%g\t",n++,g);
|
81
|
179 g = testd(g,g1);
|
427
|
180 printf("#0179:%d:%g\t",n++,g);
|
|
181 printf("#0180:\n");
|
79
|
182
|
427
|
183 printf("#0182:simple float ");
|
79
|
184 f = f+f;
|
427
|
185 printf("#0184:%d:%g\t",n++,f);
|
79
|
186 f1 = f*f;
|
427
|
187 printf("#0186:%d:%g\t",n++,f1);
|
79
|
188 f = f/f1;
|
427
|
189 printf("#0188:%d:%g\t",n++,f);
|
79
|
190 f = f-f1;
|
427
|
191 printf("#0190:%d:%g\t",n++,f);
|
79
|
192 f = sin(f1);
|
427
|
193 printf("#0192:%d:%g\t",n++,f);
|
|
194 printf("#0193:\n");
|
85
|
195
|
427
|
196 printf("#0195:post/pre increment ");
|
86
|
197 g1 = g;
|
427
|
198 printf("#0197:%d:%g\t",n++,g1++ - ++g);
|
85
|
199
|
86
|
200 f1 = f;
|
427
|
201 printf("#0200:%d:%g\t",n++,f1++ - ++f);
|
87
|
202
|
|
203 g1 = g;
|
427
|
204 printf("#0203:%d:%g\t",n++,g1-- - --g);
|
87
|
205
|
|
206 f1 = f;
|
427
|
207 printf("#0206:%d:%g\t",n++,f1-- - --f);
|
87
|
208
|
427
|
209 printf("#0208:\n");
|
|
210 printf("#0209:simple calc ");
|
87
|
211
|
|
212 f=0.13; g=-0.56; f1=-0.13; g1=0.56;
|
79
|
213
|
|
214 g = f+f;
|
427
|
215 printf("#0214:%d:%g\t",n++,g);
|
79
|
216 f = g*g;
|
427
|
217 printf("#0216:%d:%g\t",n++,f);
|
79
|
218 g = g*g+f*f-g1*g1;
|
427
|
219 printf("#0218:%d:%g\t",n++,g);
|
|
220 printf("#0219:\n");
|
79
|
221
|
427
|
222 printf("#0221:float argument ");
|
87
|
223 f = testf(f,f1);
|
427
|
224 printf("#0223:%d:%g\t",n++,f);
|
87
|
225
|
427
|
226 printf("#0225:\nindirect ");
|
85
|
227 n=1;
|
|
228 f = 1.3; pf=&f; pf1=&f1;
|
|
229
|
|
230 g = 1.0; pg=&g; pg1=&g1;
|
|
231 *pg = *pg+ *pg;
|
427
|
232 printf("#0231:%d:%g\t",n++,*pg);
|
85
|
233 *pg1 = *pg**pg;
|
427
|
234 printf("#0233:%d:%g\t",n++,*pg1);
|
85
|
235 *pg = *pg/ *pg1;
|
427
|
236 printf("#0235:%d:%g\t",n++,*pg);
|
85
|
237 *pg = *pg-*pg1;
|
427
|
238 printf("#0237:%d:%g\t",n++,*pg);
|
85
|
239 *pg = sin(*pg1);
|
427
|
240 printf("#0239:%d:%g\t",n++,*pg);
|
85
|
241 *pg = testd(*pg,*pg1);
|
427
|
242 printf("#0241:%d:%g\t",n++,*pg);
|
|
243 printf("#0242:\n");
|
85
|
244
|
|
245 *pf = *pf+*pf;
|
427
|
246 printf("#0245:%d:%g\t",n++,*pf);
|
85
|
247 *pf1 = *pf**pf;
|
427
|
248 printf("#0247:%d:%g\t",n++,*pf1);
|
85
|
249 *pf = *pf/ *pf1;
|
427
|
250 printf("#0249:%d:%g\t",n++,*pf);
|
85
|
251 *pf = *pf-*pf1;
|
427
|
252 printf("#0251:%d:%g\t",n++,*pf);
|
85
|
253 *pf = sin(*pf1);
|
427
|
254 printf("#0253:%d:%g\t",n++,*pf);
|
|
255 printf("#0254:\n");
|
85
|
256
|
427
|
257 printf("#0256:indirect post/pre ");
|
86
|
258 *pg1 = *pg;
|
427
|
259 printf("#0258:%d:%g\t",n++,(*pg1)++ - ++(*pg));
|
85
|
260
|
86
|
261 *pf1 = *pf;
|
427
|
262 printf("#0261:%d:%g\t",n++,(*pf1)++ - ++(*pf));
|
87
|
263
|
|
264 *pg1 = *pg;
|
427
|
265 printf("#0264:%d:%g\t",n++, (*pg1)-- - --(*pg));
|
86
|
266
|
87
|
267 *pf1 = *pf;
|
427
|
268 printf("#0267:%d:%g\t",n++, (*pf1)-- - --(*pf));
|
|
269 printf("#0268:\n");
|
87
|
270
|
|
271 *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56;
|
85
|
272
|
|
273 *pg = *pf+*pf;
|
427
|
274 printf("#0273:%d:%g\t",n++,*pg);
|
85
|
275 *pf = *pg**pg;
|
427
|
276 printf("#0275:%d:%g\t",n++,*pf);
|
85
|
277 *pg = *pg**pg+*pf**pf-*pg1**pg1;
|
427
|
278 printf("#0277:%d:%g\t",n++,*pg);
|
|
279 printf("#0278:\n");
|
85
|
280
|
427
|
281 printf("#0280:float argument ");
|
87
|
282
|
|
283 *pf = testf(*pf,*pf1);
|
427
|
284 printf("#0283:%d:%g\t",n++,*pf);
|
87
|
285
|
|
286
|
427
|
287 printf("#0286:\nassop ");
|
85
|
288 n=1;
|
|
289 f = 1.3;
|
|
290 g = 1.0;
|
|
291
|
|
292 g *= 2*g;
|
427
|
293 printf("#0292:%d:%g\t",n++,g);
|
85
|
294 g /= 2*g;
|
427
|
295 printf("#0294:%d:%g\t",n++,g);
|
85
|
296 g -= 2*g;
|
427
|
297 printf("#0296:%d:%g\t",n++,g);
|
85
|
298 g += 2*g;
|
427
|
299 printf("#0298:%d:%g\t",n++,g);
|
85
|
300
|
|
301 f *= 2*g;
|
427
|
302 printf("#0301:%d:%g\t",n++,f);
|
85
|
303 f /= 2*g;
|
427
|
304 printf("#0303:%d:%g\t",n++,f);
|
85
|
305 f -= 2*g;
|
427
|
306 printf("#0305:%d:%g\t",n++,f);
|
85
|
307 f += 2*g;
|
427
|
308 printf("#0307:%d:%g\t",n++,f);
|
|
309 printf("#0308:\n");
|
85
|
310
|
|
311 n=1;
|
|
312 f = 1.3;
|
|
313 g = 1.0;
|
|
314
|
427
|
315 printf("#0314:indirect assop ");
|
85
|
316 *pg *= 2**pg;
|
427
|
317 printf("#0316:%d:%g\t",n++,*pg);
|
85
|
318 *pg /= 2**pg;
|
427
|
319 printf("#0318:%d:%g\t",n++,*pg);
|
85
|
320 *pg -= 2**pg;
|
427
|
321 printf("#0320:%d:%g\t",n++,*pg);
|
85
|
322 *pg += 2**pg;
|
427
|
323 printf("#0322:%d:%g\t",n++,*pg);
|
85
|
324
|
|
325 *pf *= 2**pg;
|
427
|
326 printf("#0325:%d:%g\t",n++,*pf);
|
85
|
327 *pf /= 2**pg;
|
427
|
328 printf("#0327:%d:%g\t",n++,*pf);
|
85
|
329 *pf -= 2**pg;
|
427
|
330 printf("#0329:%d:%g\t",n++,*pf);
|
85
|
331 *pf += 2**pg;
|
427
|
332 printf("#0331:%d:%g\t",n++,*pf);
|
|
333 printf("#0332:\n");
|
85
|
334
|
|
335
|
79
|
336 return;
|
|
337 }
|
94
|
338
|
|
339 double
|
|
340 test2(double f,int i)
|
|
341 {
|
|
342 double g,h;
|
|
343
|
|
344 if (i<=0) return f;
|
112
|
345 #if 1
|
427
|
346 printf("#0345:rec: %d %g\n",i,f);
|
112
|
347 #endif
|
94
|
348 g = f*2;
|
|
349 h = f-0.5;
|
|
350 return h/3-(3.0-(g+3)*test2(f*0.5,i-1)/(h-1));
|
|
351 }
|