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
|
79
|
38 int
|
|
39 main(int ac,char *av[]) {
|
82
|
40 double g;
|
|
41 int i;
|
85
|
42 unsigned u;
|
108
|
43 double d00 = ac?0.5:3;
|
|
44
|
|
45 printf("%g\n",d00);
|
82
|
46
|
|
47 g = 1.0;
|
|
48 g = -g;
|
232
|
49 printf("%d\ncond0 ",1);
|
|
50 if(f==f*1.0) printf("t ");
|
|
51 printf("%d\ncond1 ",f==f*1.0);
|
|
52 if(d==f*1.0) printf("t ");
|
|
53 printf("%d\ncond2 ",d==f*1.0);
|
|
54 if(f==f1) printf("t ");
|
|
55 printf("%d\ncond3 ",f==f1);
|
|
56 if(d==d1) printf("t ");
|
|
57 printf("%d\ncond4 ",d==d2);
|
|
58 if(d==d2) printf("t ");
|
|
59 printf("%d\ncond5 ",(d==d2));
|
|
60 if(d>d1) printf("t ");
|
|
61 printf("%d\ncond6 ",d>d1);
|
|
62 if(d>d2) printf("t ");
|
|
63 printf("%d\ncond7 ",d>d2);
|
|
64 if(d>=d1) printf("t ");
|
|
65 printf("%d\ncond8 ",d>=d1);
|
|
66 if(d>=d2) printf("t ");
|
|
67 printf("%d\ncond9 ",d>=d2);
|
|
68 if(d!=d1) printf("t ");
|
|
69 printf("%d\ncond10 ",d!=d1);
|
|
70 if(d!=d2) printf("5 ");
|
|
71 printf("%d\ncond11 ",d!=d2);
|
|
72 if(d<d1) printf("t ");
|
|
73 printf("%d\ncond12 ",d<d1);
|
|
74 if(d<d2) printf("t ");
|
|
75 printf("%d\ncond13 ",d<d2);
|
|
76 if(d<=d1) printf("t ");
|
|
77 printf("%d\ncond14 ",d<=d1);
|
|
78 if(d<=d2) printf("t ");
|
|
79 printf("%d\ncond15 ",d<=d2);
|
85
|
80 d = 123.4234; f=-234.333;
|
82
|
81 i = d;
|
|
82 d = i;
|
|
83 i = f;
|
|
84 f = i;
|
276
|
85 printf("\ni=%d d=%g f=%f",i,d,f);
|
94
|
86 f = g = d = d1 = d2 = f;
|
276
|
87 printf(" i=%d d=%g f=%f g=%g\n",i,d,f,g);
|
82
|
88
|
86
|
89 d = 4204967294.4234; f=4204967294.4234;
|
85
|
90 u = d;
|
284
|
91 printf("1: u=%u d=%g f=%f\n",u,d,f);
|
85
|
92 d = u;
|
284
|
93 printf("2: u=%u d=%g f=%f\n",u,d,f);
|
85
|
94 u = f;
|
284
|
95 printf("3: u=%u d=%g f=%f\n",u,d,f);
|
85
|
96 f = u;
|
284
|
97 printf("4: u=%u d=%g f=%f\n",u,d,f);
|
85
|
98
|
82
|
99 print(1.0);
|
|
100 print(0.1234);
|
|
101 print(1.234e10);
|
|
102 print(1.234e-10);
|
|
103
|
79
|
104 test1();
|
94
|
105 printf("nested call: %g\n",test2(test2(test2(test2(-0.333,3),5),6),7));
|
79
|
106 return 0;
|
|
107 }
|
|
108
|
82
|
109 void
|
|
110 print(double d)
|
|
111 {
|
|
112 float f;
|
|
113 int *dd;
|
|
114
|
|
115 f = d;
|
|
116
|
|
117 dd = (int*) &d;
|
84
|
118 printf("d %g ",d);
|
82
|
119 printf("dx %08x %08x\n",*(dd),*(dd+1));
|
|
120
|
|
121 dd = (int*) &f;
|
84
|
122 printf("f %g ",f);
|
82
|
123 printf("dx %08x \n",*(dd));
|
|
124 }
|
|
125
|
81
|
126 double
|
|
127 testd(double i,double j)
|
|
128 {
|
87
|
129 return j+1.1+.0e3+12.3e-12;
|
81
|
130 }
|
|
131
|
|
132 float
|
|
133 testf(float i,float j)
|
|
134 {
|
87
|
135 return j+1;
|
81
|
136 }
|
|
137
|
79
|
138 void
|
|
139 test1()
|
|
140 {
|
|
141 float f;
|
|
142 float f1;
|
|
143 double g;
|
|
144 double g1;
|
85
|
145 float *pf;
|
|
146 float *pf1;
|
|
147 double *pg;
|
|
148 double *pg1;
|
|
149 int n = 1;
|
79
|
150
|
87
|
151 printf("simple double ");
|
79
|
152 f = 1.3;
|
|
153
|
|
154 g = 1.0;
|
|
155 g = g+g;
|
85
|
156 printf("%d:%g\t",n++,g);
|
79
|
157 g1 = g*g;
|
85
|
158 printf("%d:%g\t",n++,g1);
|
79
|
159 g = g/g1;
|
85
|
160 printf("%d:%g\t",n++,g);
|
79
|
161 g = g-g1;
|
85
|
162 printf("%d:%g\t",n++,g);
|
79
|
163 g = sin(g1);
|
85
|
164 printf("%d:%g\t",n++,g);
|
81
|
165 g = testd(g,g1);
|
85
|
166 printf("%d:%g\t",n++,g);
|
|
167 printf("\n");
|
79
|
168
|
87
|
169 printf("simple float ");
|
79
|
170 f = f+f;
|
85
|
171 printf("%d:%g\t",n++,f);
|
79
|
172 f1 = f*f;
|
85
|
173 printf("%d:%g\t",n++,f1);
|
79
|
174 f = f/f1;
|
85
|
175 printf("%d:%g\t",n++,f);
|
79
|
176 f = f-f1;
|
85
|
177 printf("%d:%g\t",n++,f);
|
79
|
178 f = sin(f1);
|
85
|
179 printf("%d:%g\t",n++,f);
|
|
180 printf("\n");
|
|
181
|
87
|
182 printf("post/pre increment ");
|
86
|
183 g1 = g;
|
87
|
184 printf("%d:%g\t",n++,g1++ - ++g);
|
85
|
185
|
86
|
186 f1 = f;
|
87
|
187 printf("%d:%g\t",n++,f1++ - ++f);
|
|
188
|
|
189 g1 = g;
|
|
190 printf("%d:%g\t",n++,g1-- - --g);
|
|
191
|
|
192 f1 = f;
|
|
193 printf("%d:%g\t",n++,f1-- - --f);
|
|
194
|
|
195 printf("\n");
|
|
196 printf("simple calc ");
|
|
197
|
|
198 f=0.13; g=-0.56; f1=-0.13; g1=0.56;
|
79
|
199
|
|
200 g = f+f;
|
85
|
201 printf("%d:%g\t",n++,g);
|
79
|
202 f = g*g;
|
85
|
203 printf("%d:%g\t",n++,f);
|
79
|
204 g = g*g+f*f-g1*g1;
|
85
|
205 printf("%d:%g\t",n++,g);
|
|
206 printf("\n");
|
79
|
207
|
87
|
208 printf("float argument ");
|
|
209 f = testf(f,f1);
|
|
210 printf("%d:%g\t",n++,f);
|
|
211
|
|
212 printf("\nindirect ");
|
85
|
213 n=1;
|
|
214 f = 1.3; pf=&f; pf1=&f1;
|
|
215
|
|
216 g = 1.0; pg=&g; pg1=&g1;
|
|
217 *pg = *pg+ *pg;
|
|
218 printf("%d:%g\t",n++,*pg);
|
|
219 *pg1 = *pg**pg;
|
|
220 printf("%d:%g\t",n++,*pg1);
|
|
221 *pg = *pg/ *pg1;
|
|
222 printf("%d:%g\t",n++,*pg);
|
|
223 *pg = *pg-*pg1;
|
|
224 printf("%d:%g\t",n++,*pg);
|
|
225 *pg = sin(*pg1);
|
|
226 printf("%d:%g\t",n++,*pg);
|
|
227 *pg = testd(*pg,*pg1);
|
|
228 printf("%d:%g\t",n++,*pg);
|
|
229 printf("\n");
|
|
230
|
|
231 *pf = *pf+*pf;
|
|
232 printf("%d:%g\t",n++,*pf);
|
|
233 *pf1 = *pf**pf;
|
|
234 printf("%d:%g\t",n++,*pf1);
|
|
235 *pf = *pf/ *pf1;
|
|
236 printf("%d:%g\t",n++,*pf);
|
|
237 *pf = *pf-*pf1;
|
|
238 printf("%d:%g\t",n++,*pf);
|
|
239 *pf = sin(*pf1);
|
|
240 printf("%d:%g\t",n++,*pf);
|
|
241 printf("\n");
|
|
242
|
87
|
243 printf("indirect post/pre ");
|
86
|
244 *pg1 = *pg;
|
87
|
245 printf("%d:%g\t",n++,(*pg1)++ - ++(*pg));
|
85
|
246
|
86
|
247 *pf1 = *pf;
|
87
|
248 printf("%d:%g\t",n++,(*pf1)++ - ++(*pf));
|
|
249
|
|
250 *pg1 = *pg;
|
|
251 printf("%d:%g\t",n++, (*pg1)-- - --(*pg));
|
86
|
252
|
87
|
253 *pf1 = *pf;
|
|
254 printf("%d:%g\t",n++, (*pf1)-- - --(*pf));
|
|
255 printf("\n");
|
|
256
|
|
257 *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56;
|
85
|
258
|
|
259 *pg = *pf+*pf;
|
|
260 printf("%d:%g\t",n++,*pg);
|
|
261 *pf = *pg**pg;
|
|
262 printf("%d:%g\t",n++,*pf);
|
|
263 *pg = *pg**pg+*pf**pf-*pg1**pg1;
|
|
264 printf("%d:%g\t",n++,*pg);
|
|
265 printf("\n");
|
|
266
|
87
|
267 printf("float argument ");
|
|
268
|
|
269 *pf = testf(*pf,*pf1);
|
|
270 printf("%d:%g\t",n++,*pf);
|
|
271
|
|
272
|
|
273 printf("\nassop ");
|
85
|
274 n=1;
|
|
275 f = 1.3;
|
|
276 g = 1.0;
|
|
277
|
|
278 g *= 2*g;
|
|
279 printf("%d:%g\t",n++,g);
|
|
280 g /= 2*g;
|
|
281 printf("%d:%g\t",n++,g);
|
|
282 g -= 2*g;
|
|
283 printf("%d:%g\t",n++,g);
|
|
284 g += 2*g;
|
|
285 printf("%d:%g\t",n++,g);
|
|
286
|
|
287 f *= 2*g;
|
|
288 printf("%d:%g\t",n++,f);
|
|
289 f /= 2*g;
|
|
290 printf("%d:%g\t",n++,f);
|
|
291 f -= 2*g;
|
|
292 printf("%d:%g\t",n++,f);
|
|
293 f += 2*g;
|
|
294 printf("%d:%g\t",n++,f);
|
|
295 printf("\n");
|
|
296
|
|
297 n=1;
|
|
298 f = 1.3;
|
|
299 g = 1.0;
|
|
300
|
87
|
301 printf("indirect assop ");
|
85
|
302 *pg *= 2**pg;
|
|
303 printf("%d:%g\t",n++,*pg);
|
|
304 *pg /= 2**pg;
|
|
305 printf("%d:%g\t",n++,*pg);
|
|
306 *pg -= 2**pg;
|
|
307 printf("%d:%g\t",n++,*pg);
|
|
308 *pg += 2**pg;
|
|
309 printf("%d:%g\t",n++,*pg);
|
|
310
|
|
311 *pf *= 2**pg;
|
|
312 printf("%d:%g\t",n++,*pf);
|
|
313 *pf /= 2**pg;
|
|
314 printf("%d:%g\t",n++,*pf);
|
|
315 *pf -= 2**pg;
|
|
316 printf("%d:%g\t",n++,*pf);
|
|
317 *pf += 2**pg;
|
|
318 printf("%d:%g\t",n++,*pf);
|
|
319 printf("\n");
|
|
320
|
|
321
|
79
|
322 return;
|
|
323 }
|
94
|
324
|
|
325 double
|
|
326 test2(double f,int i)
|
|
327 {
|
|
328 double g,h;
|
|
329
|
|
330 if (i<=0) return f;
|
112
|
331 #if 1
|
|
332 printf("rec: %d %g\n",i,f);
|
|
333 #endif
|
94
|
334 g = f*2;
|
|
335 h = f-0.5;
|
|
336 return h/3-(3.0-(g+3)*test2(f*0.5,i-1)/(h-1));
|
|
337 }
|