comparison test/float.c @ 491:a379da780856

cond signed/unsigned
author kono
date Wed, 21 Dec 2005 11:33:53 +0900
parents 51c1b795b4f3
children fcb642ef08c9
comparison
equal deleted inserted replaced
490:95fcc858fd1c 491:a379da780856
51 } 51 }
52 52
53 void 53 void
54 test1(float id, float x,float y,float sx,float sy,int behav) 54 test1(float id, float x,float y,float sx,float sy,int behav)
55 { 55 {
56 printf("%f %f %f %f %f %d\n", id,x,y,sx,sy,behav); 56 printf("#0055:%f %f %f %f %f %d\n", id,x,y,sx,sy,behav);
57 } 57 }
58 58
59 void 59 void
60 test2(int id, int x,float y,float sx,float sy,int behav) 60 test2(int id, int x,float y,float sx,float sy,int behav)
61 { 61 {
62 printf("%d %d %f %f %f %d\n", id,x,y,sx,sy,behav); 62 printf("#0061:%d %d %f %f %f %d\n", id,x,y,sx,sy,behav);
63 } 63 }
64 64
65 void 65 void
66 test3(int id, float x,float y,float sx,float sy,int behav) 66 test3(int id, float x,float y,float sx,float sy,int behav)
67 { 67 {
68 printf("%d %f %f %f %f %d\n", id,x,y,sx,sy,behav); 68 printf("#0067:%d %f %f %f %f %d\n", id,x,y,sx,sy,behav);
69 } 69 }
70 70
71 void 71 void
72 test4(int id, float x,int y,float sx,float sy,int behav) 72 test4(int id, float x,int y,float sx,float sy,int behav)
73 { 73 {
74 printf("%d %f %d %f %f %d\n", id,x,y,sx,sy,behav); 74 printf("#0073:%d %f %d %f %f %d\n", id,x,y,sx,sy,behav);
75 } 75 }
76 76
77 void 77 void
78 test5(float id, int x,float y,int sx,float sy,int behav) 78 test5(float id, int x,float y,int sx,float sy,int behav)
79 { 79 {
80 printf("%f %d %f %d %f %d\n", id,x,y,sx,sy,behav); 80 printf("#0079:%f %d %f %d %f %d\n", id,x,y,sx,sy,behav);
81 } 81 }
82 82
83 83
84 84
85 int 85 int
87 double g; 87 double g;
88 int i; 88 int i;
89 unsigned u; 89 unsigned u;
90 double d00 = ac?0.5:3; 90 double d00 = ac?0.5:3;
91 91
92 printf("#0058:%g\n",d00); 92 printf("#0091:%g\n",d00);
93 93
94 test1(1,2,3,10,11,4); 94 test1(1,2,3,10,11,4);
95 test2(1,2,3,10,11,4); 95 test2(1,2,3,10,11,4);
96 test3(1,2,3,10,11,4); 96 test3(1,2,3,10,11,4);
97 test4(1,2,3,10,11,4); 97 test4(1,2,3,10,11,4);
98 test5(1,2,3,10,11,4); 98 test5(1,2,3,10,11,4);
99 test7(); 99 test7();
100 100
101 g = 1.0; 101 g = 1.0;
102 g = -g; 102 g = -g;
103 printf("#0062:%d\ncond0 ",1); 103 printf("#0102:%d\ncond0 ",1);
104 if(f==f*1.0) printf("#0063:t "); 104 if(f==f*1.0) printf("#0103:t ");
105 printf("#0064:%d\ncond1 ",f==f*1.0); 105 printf("#0104:%d\ncond1 ",f==f*1.0);
106 if(d==f*1.0) printf("#0065:t "); 106 if(d==f*1.0) printf("#0105:t ");
107 printf("#0066:%d\ncond2 ",d==f*1.0); 107 printf("#0106:%d\ncond2 ",d==f*1.0);
108 if(f==f1) printf("#0067:t "); 108 if(f==f1) printf("#0107:t ");
109 printf("#0068:%d\ncond3 ",f==f1); 109 printf("#0108:%d\ncond3 ",f==f1);
110 if(d==d1) printf("#0069:t "); 110 if(d==d1) printf("#0109:t ");
111 printf("#0070:%d\ncond4 ",d==d2); 111 printf("#0110:%d\ncond4 ",d==d2);
112 if(d==d2) printf("#0071:t "); 112 if(d==d2) printf("#0111:t ");
113 printf("#0072:%d\ncond5 ",(d==d2)); 113 printf("#0112:%d\ncond5 ",(d==d2));
114 if(d>d1) printf("#0073:t "); 114 if(d>d1) printf("#0113:t ");
115 printf("#0074:%d\ncond6 ",d>d1); 115 printf("#0114:%d\ncond6 ",d>d1);
116 if(d>d2) printf("#0075:t "); 116 if(d>d2) printf("#0115:t ");
117 printf("#0076:%d\ncond7 ",d>d2); 117 printf("#0116:%d\ncond7 ",d>d2);
118 if(d>=d1) printf("#0077:t "); 118 if(d>=d1) printf("#0117:t ");
119 printf("#0078:%d\ncond8 ",d>=d1); 119 printf("#0118:%d\ncond8 ",d>=d1);
120 if(d>=d2) printf("#0079:t "); 120 if(d>=d2) printf("#0119:t ");
121 printf("#0080:%d\ncond9 ",d>=d2); 121 printf("#0120:%d\ncond9 ",d>=d2);
122 if(d!=d1) printf("#0081:t "); 122 if(d!=d1) printf("#0121:t ");
123 printf("#0082:%d\ncond10 ",d!=d1); 123 printf("#0122:%d\ncond10 ",d!=d1);
124 if(d!=d2) printf("#0083:5 "); 124 if(d!=d2) printf("#0123:5 ");
125 printf("#0084:%d\ncond11 ",d!=d2); 125 printf("#0124:%d\ncond11 ",d!=d2);
126 if(d<d1) printf("#0085:t "); 126 if(d<d1) printf("#0125:t ");
127 printf("#0086:%d\ncond12 ",d<d1); 127 printf("#0126:%d\ncond12 ",d<d1);
128 if(d<d2) printf("#0087:t "); 128 if(d<d2) printf("#0127:t ");
129 printf("#0088:%d\ncond13 ",d<d2); 129 printf("#0128:%d\ncond13 ",d<d2);
130 if(d<=d1) printf("#0089:t "); 130 if(d<=d1) printf("#0129:t ");
131 printf("#0090:%d\ncond14 ",d<=d1); 131 printf("#0130:%d\ncond14 ",d<=d1);
132 if(d<=d2) printf("#0091:t "); 132 if(d<=d2) printf("#0131:t ");
133 printf("#0092:%d\ncond15 ",d<=d2); 133 printf("#0132:%d\ncond15 ",d<=d2);
134 d = 123.4234; f=-234.333; 134 d = 123.4234; f=-234.333;
135 i = d; 135 i = d;
136 d = i; 136 d = i;
137 i = f; 137 i = f;
138 f = i; 138 f = i;
139 printf("#0098:\ni=%d d=%g f=%f",i,d,f); 139 printf("#0138:\ni=%d d=%g f=%f",i,d,f);
140 f = g = d = d1 = d2 = f; 140 f = g = d = d1 = d2 = f;
141 printf("#0100: i=%d d=%g f=%f g=%g\n",i,d,f,g); 141 printf("#0140: i=%d d=%g f=%f g=%g\n",i,d,f,g);
142 142
143 d = 4204967294.4234; f=4204967294.4234; 143 d = 4204967294.4234; f=4204967294.4234;
144 u = d; 144 u = d;
145 printf("#0104:1: u=%u d=%g f=%f\n",u,d,f); 145 printf("#0144:1: u=%u d=%g f=%f\n",u,d,f);
146 d = u; 146 d = u;
147 printf("#0106:2: u=%u d=%g f=%f\n",u,d,f); 147 printf("#0146:2: u=%u d=%g f=%f\n",u,d,f);
148 u = f; 148 u = f;
149 printf("#0108:3: u=%u d=%g f=%f\n",u,d,f); 149 printf("#0148:3: u=%u d=%g f=%f\n",u,d,f);
150 f = u; 150 f = u;
151 printf("#0110:4: u=%u d=%g f=%f\n",u,d,f); 151 printf("#0150:4: u=%u d=%g f=%f\n",u,d,f);
152 152
153 print(1.0); 153 print(1.0);
154 print(0.1234); 154 print(0.1234);
155 print(1.234e10); 155 print(1.234e10);
156 print(1.234e-10); 156 print(1.234e-10);
157 157
158 test8(); 158 test8();
159 printf("#0118:nested call: %g\n",test9(test9(test9(test9(-0.333,3),5),6),7)); 159 printf("#0158:nested call: %g\n",test9(test9(test9(test9(-0.333,3),5),6),7));
160 return 0; 160 return 0;
161 } 161 }
162 162
163 void 163 void
164 print(double d) 164 print(double d)
167 int *dd; 167 int *dd;
168 168
169 f = d; 169 f = d;
170 170
171 dd = (int*) &d; 171 dd = (int*) &d;
172 printf("#0131:d %g ",d); 172 printf("#0171:d %g ",d);
173 printf("#0132:dx %08x %08x\n",*(dd),*(dd+1)); 173 printf("#0172:dx %08x %08x\n",*(dd),*(dd+1));
174 174
175 dd = (int*) &f; 175 dd = (int*) &f;
176 printf("#0135:f %g ",f); 176 printf("#0175:f %g ",f);
177 printf("#0136:dx %08x \n",*(dd)); 177 printf("#0176:dx %08x \n",*(dd));
178 } 178 }
179 179
180 double 180 double
181 testd(double i,double j) 181 testd(double i,double j)
182 { 182 {
200 float *pf1; 200 float *pf1;
201 double *pg; 201 double *pg;
202 double *pg1; 202 double *pg1;
203 int n = 1; 203 int n = 1;
204 204
205 printf("#0164:simple double "); 205 printf("#0204:simple double ");
206 f = 1.3; 206 f = 1.3;
207 207
208 g = 1.0; 208 g = 1.0;
209 g = g+g; 209 g = g+g;
210 printf("#0169:%d:%g\t",n++,g); 210 printf("#0209:%d:%g\t",n++,g);
211 g1 = g*g; 211 g1 = g*g;
212 printf("#0171:%d:%g\t",n++,g1); 212 printf("#0211:%d:%g\t",n++,g1);
213 g = g/g1; 213 g = g/g1;
214 printf("#0173:%d:%g\t",n++,g); 214 printf("#0213:%d:%g\t",n++,g);
215 g = g-g1; 215 g = g-g1;
216 printf("#0175:%d:%g\t",n++,g); 216 printf("#0215:%d:%g\t",n++,g);
217 g = sin(g1); 217 g = sin(g1);
218 printf("#0177:%d:%g\t",n++,g); 218 printf("#0217:%d:%g\t",n++,g);
219 g = testd(g,g1); 219 g = testd(g,g1);
220 printf("#0179:%d:%g\t",n++,g); 220 printf("#0219:%d:%g\t",n++,g);
221 printf("#0180:\n"); 221 printf("#0220:\n");
222 222
223 printf("#0182:simple float "); 223 printf("#0222:simple float ");
224 f = f+f; 224 f = f+f;
225 printf("#0184:%d:%g\t",n++,f); 225 printf("#0224:%d:%g\t",n++,f);
226 f1 = f*f; 226 f1 = f*f;
227 printf("#0186:%d:%g\t",n++,f1); 227 printf("#0226:%d:%g\t",n++,f1);
228 f = f/f1; 228 f = f/f1;
229 printf("#0188:%d:%g\t",n++,f); 229 printf("#0228:%d:%g\t",n++,f);
230 f = f-f1; 230 f = f-f1;
231 printf("#0190:%d:%g\t",n++,f); 231 printf("#0230:%d:%g\t",n++,f);
232 f = sin(f1); 232 f = sin(f1);
233 printf("#0192:%d:%g\t",n++,f); 233 printf("#0232:%d:%g\t",n++,f);
234 printf("#0193:\n"); 234 printf("#0233:\n");
235 235
236 printf("#0195:post/pre increment "); 236 printf("#0235:post/pre increment ");
237 g1 = g; 237 g1 = g;
238 printf("#0197:%d:%g\t",n++,g1++ - ++g); 238 printf("#0237:%d:%g\t",n++,g1++ - ++g);
239 239
240 f1 = f; 240 f1 = f;
241 printf("#0200:%d:%g\t",n++,f1++ - ++f); 241 printf("#0240:%d:%g\t",n++,f1++ - ++f);
242 242
243 g1 = g; 243 g1 = g;
244 printf("#0203:%d:%g\t",n++,g1-- - --g); 244 printf("#0243:%d:%g\t",n++,g1-- - --g);
245 245
246 f1 = f; 246 f1 = f;
247 printf("#0206:%d:%g\t",n++,f1-- - --f); 247 printf("#0246:%d:%g\t",n++,f1-- - --f);
248 248
249 printf("#0208:\n"); 249 printf("#0248:\n");
250 printf("#0209:simple calc "); 250 printf("#0249:simple calc ");
251 251
252 f=0.13; g=-0.56; f1=-0.13; g1=0.56; 252 f=0.13; g=-0.56; f1=-0.13; g1=0.56;
253 253
254 g = f+f; 254 g = f+f;
255 printf("#0214:%d:%g\t",n++,g); 255 printf("#0254:%d:%g\t",n++,g);
256 f = g*g; 256 f = g*g;
257 printf("#0216:%d:%g\t",n++,f); 257 printf("#0256:%d:%g\t",n++,f);
258 g = g*g+f*f-g1*g1; 258 g = g*g+f*f-g1*g1;
259 printf("#0218:%d:%g\t",n++,g); 259 printf("#0258:%d:%g\t",n++,g);
260 printf("#0219:\n"); 260 printf("#0259:\n");
261 261
262 printf("#0221:float argument "); 262 printf("#0261:float argument ");
263 f = testf(f,f1); 263 f = testf(f,f1);
264 printf("#0223:%d:%g\t",n++,f); 264 printf("#0263:%d:%g\t",n++,f);
265 265
266 printf("#0225:\nindirect "); 266 printf("#0265:\nindirect ");
267 n=1; 267 n=1;
268 f = 1.3; pf=&f; pf1=&f1; 268 f = 1.3; pf=&f; pf1=&f1;
269 269
270 g = 1.0; pg=&g; pg1=&g1; 270 g = 1.0; pg=&g; pg1=&g1;
271 *pg = *pg+ *pg; 271 *pg = *pg+ *pg;
272 printf("#0231:%d:%g\t",n++,*pg); 272 printf("#0271:%d:%g\t",n++,*pg);
273 *pg1 = *pg**pg; 273 *pg1 = *pg**pg;
274 printf("#0233:%d:%g\t",n++,*pg1); 274 printf("#0273:%d:%g\t",n++,*pg1);
275 *pg = *pg/ *pg1; 275 *pg = *pg/ *pg1;
276 printf("#0235:%d:%g\t",n++,*pg); 276 printf("#0275:%d:%g\t",n++,*pg);
277 *pg = *pg-*pg1; 277 *pg = *pg-*pg1;
278 printf("#0237:%d:%g\t",n++,*pg); 278 printf("#0277:%d:%g\t",n++,*pg);
279 *pg = sin(*pg1); 279 *pg = sin(*pg1);
280 printf("#0239:%d:%g\t",n++,*pg); 280 printf("#0279:%d:%g\t",n++,*pg);
281 *pg = testd(*pg,*pg1); 281 *pg = testd(*pg,*pg1);
282 printf("#0241:%d:%g\t",n++,*pg); 282 printf("#0281:%d:%g\t",n++,*pg);
283 printf("#0242:\n"); 283 printf("#0282:\n");
284 284
285 *pf = *pf+*pf; 285 *pf = *pf+*pf;
286 printf("#0245:%d:%g\t",n++,*pf); 286 printf("#0285:%d:%g\t",n++,*pf);
287 *pf1 = *pf**pf; 287 *pf1 = *pf**pf;
288 printf("#0247:%d:%g\t",n++,*pf1); 288 printf("#0287:%d:%g\t",n++,*pf1);
289 *pf = *pf/ *pf1; 289 *pf = *pf/ *pf1;
290 printf("#0249:%d:%g\t",n++,*pf); 290 printf("#0289:%d:%g\t",n++,*pf);
291 *pf = *pf-*pf1; 291 *pf = *pf-*pf1;
292 printf("#0251:%d:%g\t",n++,*pf); 292 printf("#0291:%d:%g\t",n++,*pf);
293 *pf = sin(*pf1); 293 *pf = sin(*pf1);
294 printf("#0253:%d:%g\t",n++,*pf); 294 printf("#0293:%d:%g\t",n++,*pf);
295 printf("#0254:\n"); 295 printf("#0294:\n");
296 296
297 printf("#0256:indirect post/pre "); 297 printf("#0296:indirect post/pre ");
298 *pg1 = *pg; 298 *pg1 = *pg;
299 printf("#0258:%d:%g\t",n++,(*pg1)++ - ++(*pg)); 299 printf("#0298:%d:%g\t",n++,(*pg1)++ - ++(*pg));
300 300
301 *pf1 = *pf; 301 *pf1 = *pf;
302 printf("#0261:%d:%g\t",n++,(*pf1)++ - ++(*pf)); 302 printf("#0301:%d:%g\t",n++,(*pf1)++ - ++(*pf));
303 303
304 *pg1 = *pg; 304 *pg1 = *pg;
305 printf("#0264:%d:%g\t",n++, (*pg1)-- - --(*pg)); 305 printf("#0304:%d:%g\t",n++, (*pg1)-- - --(*pg));
306 306
307 *pf1 = *pf; 307 *pf1 = *pf;
308 printf("#0267:%d:%g\t",n++, (*pf1)-- - --(*pf)); 308 printf("#0307:%d:%g\t",n++, (*pf1)-- - --(*pf));
309 printf("#0268:\n"); 309 printf("#0308:\n");
310 310
311 *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56; 311 *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56;
312 312
313 *pg = *pf+*pf; 313 *pg = *pf+*pf;
314 printf("#0273:%d:%g\t",n++,*pg); 314 printf("#0313:%d:%g\t",n++,*pg);
315 *pf = *pg**pg; 315 *pf = *pg**pg;
316 printf("#0275:%d:%g\t",n++,*pf); 316 printf("#0315:%d:%g\t",n++,*pf);
317 *pg = *pg**pg+*pf**pf-*pg1**pg1; 317 *pg = *pg**pg+*pf**pf-*pg1**pg1;
318 printf("#0277:%d:%g\t",n++,*pg); 318 printf("#0317:%d:%g\t",n++,*pg);
319 printf("#0278:\n"); 319 printf("#0318:\n");
320 320
321 printf("#0280:float argument "); 321 printf("#0320:float argument ");
322 322
323 *pf = testf(*pf,*pf1); 323 *pf = testf(*pf,*pf1);
324 printf("#0283:%d:%g\t",n++,*pf); 324 printf("#0323:%d:%g\t",n++,*pf);
325 325
326 326
327 printf("#0286:\nassop "); 327 printf("#0326:\nassop ");
328 n=1; 328 n=1;
329 f = 1.3; 329 f = 1.3;
330 g = 1.0; 330 g = 1.0;
331 331
332 g *= 2*g; 332 g *= 2*g;
333 printf("#0292:%d:%g\t",n++,g); 333 printf("#0332:%d:%g\t",n++,g);
334 g /= 2*g; 334 g /= 2*g;
335 printf("#0294:%d:%g\t",n++,g); 335 printf("#0334:%d:%g\t",n++,g);
336 g -= 2*g; 336 g -= 2*g;
337 printf("#0296:%d:%g\t",n++,g); 337 printf("#0336:%d:%g\t",n++,g);
338 g += 2*g; 338 g += 2*g;
339 printf("#0298:%d:%g\t",n++,g); 339 printf("#0338:%d:%g\t",n++,g);
340 340
341 f *= 2*g; 341 f *= 2*g;
342 printf("#0301:%d:%g\t",n++,f); 342 printf("#0341:%d:%g\t",n++,f);
343 f /= 2*g; 343 f /= 2*g;
344 printf("#0303:%d:%g\t",n++,f); 344 printf("#0343:%d:%g\t",n++,f);
345 f -= 2*g; 345 f -= 2*g;
346 printf("#0305:%d:%g\t",n++,f); 346 printf("#0345:%d:%g\t",n++,f);
347 f += 2*g; 347 f += 2*g;
348 printf("#0307:%d:%g\t",n++,f); 348 printf("#0347:%d:%g\t",n++,f);
349 printf("#0308:\n"); 349 printf("#0348:\n");
350 350
351 n=1; 351 n=1;
352 f = 1.3; 352 f = 1.3;
353 g = 1.0; 353 g = 1.0;
354 354
355 printf("#0314:indirect assop "); 355 printf("#0354:indirect assop ");
356 *pg *= 2**pg; 356 *pg *= 2**pg;
357 printf("#0316:%d:%g\t",n++,*pg); 357 printf("#0356:%d:%g\t",n++,*pg);
358 *pg /= 2**pg; 358 *pg /= 2**pg;
359 printf("#0318:%d:%g\t",n++,*pg); 359 printf("#0358:%d:%g\t",n++,*pg);
360 *pg -= 2**pg; 360 *pg -= 2**pg;
361 printf("#0320:%d:%g\t",n++,*pg); 361 printf("#0360:%d:%g\t",n++,*pg);
362 *pg += 2**pg; 362 *pg += 2**pg;
363 printf("#0322:%d:%g\t",n++,*pg); 363 printf("#0362:%d:%g\t",n++,*pg);
364 364
365 *pf *= 2**pg; 365 *pf *= 2**pg;
366 printf("#0325:%d:%g\t",n++,*pf); 366 printf("#0365:%d:%g\t",n++,*pf);
367 *pf /= 2**pg; 367 *pf /= 2**pg;
368 printf("#0327:%d:%g\t",n++,*pf); 368 printf("#0367:%d:%g\t",n++,*pf);
369 *pf -= 2**pg; 369 *pf -= 2**pg;
370 printf("#0329:%d:%g\t",n++,*pf); 370 printf("#0369:%d:%g\t",n++,*pf);
371 *pf += 2**pg; 371 *pf += 2**pg;
372 printf("#0331:%d:%g\t",n++,*pf); 372 printf("#0371:%d:%g\t",n++,*pf);
373 printf("#0332:\n"); 373 printf("#0372:\n");
374 374
375 375
376 return; 376 return;
377 } 377 }
378 378
381 { 381 {
382 double g,h; 382 double g,h;
383 383
384 if (i<=0) return f; 384 if (i<=0) return f;
385 #if 1 385 #if 1
386 printf("#0345:rec: %d %g\n",i,f); 386 printf("#0385:rec: %d %g\n",i,f);
387 #endif 387 #endif
388 g = f*2; 388 g = f*2;
389 h = f-0.5; 389 h = f-0.5;
390 return h/3-(3.0-(g+3)*test9(f*0.5,i-1)/(h-1)); 390 return h/3-(3.0-(g+3)*test9(f*0.5,i-1)/(h-1));
391 } 391 }
415 }; 415 };
416 416
417 void 417 void
418 print_param(struct enemy *e) 418 print_param(struct enemy *e)
419 { 419 {
420 printf("charno:%d x,y:%f,%f hp:%d\n", 420 printf("#0419:charno:%d x,y:%f,%f hp:%d\n",
421 e->charno,e->x,e->y,e->ap); 421 e->charno,e->x,e->y,e->ap);
422 } 422 }
423 423
424 424
425 int test7() 425 int test7()