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