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