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