Mercurial > hg > CbC > old > device
view test/int.c @ 928:96c53f76b360
fix
author | kono |
---|---|
date | Sun, 13 Apr 2014 10:21:40 +0900 |
parents | 5313ed059cee |
children |
line wrap: on
line source
#include "stdio.h" double sin(double); void test1(); void print(int d); int test2(int f,int i); unsigned f = 3; int d = -3; unsigned f1 = 3; unsigned f2 = 4; int d1 = -3; int d2 = -2; unsigned h = 65536*100; int d2i(int d) { return (int)d; } int i2d(int u) { return (int)u; } unsigned u; unsigned d2u(int d) { return (unsigned)d; } int u2d(unsigned u) { return (int)u; } int main(int ac,char *av[]) { int g; int i; unsigned u; unsigned d00 = ac?-30:ac; unsigned d01 = 0x3ffffff; unsigned d02 = 0x300; printf("#0046:%d %f %d %f\n",1,0.1,1,0.1); printf("#0047:%f %d %f %d\n",0.1,1,0.1,1); printf("#0049:%u %u %u\n",d00,d01%d02,d01*d02); g = 1; g = -g; printf("#0053:%d\ncond ",g); if(f==f*1) printf("#0054:1 "); if(d==f*1) printf("#0055:2 "); if(f==f1) printf("#0056:3 "); if(d==d1) printf("#0057:4 "); if(d==d2) printf("#0058:-4 "); if(d>d1) printf("#0059:5 "); if(d>d2) printf("#0060:-5 "); if(d>=d1) printf("#0061:6 "); if(d>=d2) printf("#0062:-6 "); if(d!=d1) printf("#0063:7 "); if(d!=d2) printf("#0064:-7 "); if(d<d1) printf("#0065:8 "); if(d<d2) printf("#0066:-8 "); if(d<=d1) printf("#0067:9 "); if(d<=d2) printf("#0068:-9 "); printf("#0070:unsigned "); if(f>f1) printf("#0071:5 "); if(f>f2) printf("#0072:-5 "); if(f>=f1) printf("#0073:6 "); if(f>=f2) printf("#0074:-6 "); if(f!=f1) printf("#0075:7 "); if(f!=f2) printf("#0076:-7 "); if(f<f1) printf("#0077:8 "); if(f<f2) printf("#0078:-8 "); if(f<=f1) printf("#0079:9 "); if(f<=f2) printf("#0080:-9 "); d = 123; f=-234; i = d; d = i; i = f; f = i; printf("#0087:\n%d %d %d",i,d,f); f = g = d = d1 = d2 = f; printf("#0089: %d %d %d %d\n",i,d,f,g); d = 320967294; f=224967294; u = d; d = u; u = f; f = u; printf("#0096:%u %d %d\n",u,d,f); print(1.0); print(0.1234*100); print(1.234e6); print(-1.234e+3); test1(); printf("#0104:nested call: %d\n",test2(test2(test2(test2(-333,3),5),6),7)); /* test3(40,20); */ return 0; } void print(int d) { unsigned f; int *dd; f = d; dd = (int*) &f; printf("#0119:f %d ",f); printf("#0120:dx %08x \n",*(dd)); } int testd(int i,int j) { return j+1.1+.0e3+12.3e-12; } unsigned testf(unsigned i,unsigned j) { return j+1; } void ahoaho() { } void test1() { unsigned f; unsigned f1; int g; int g1; unsigned *pf; unsigned *pf1; int *pg; int *pg1; int n = 1; printf("#0152:simple int "); f = 1.3; g = 1.0; g = g+g; printf("#0157:%d:%d\t",n++,g); g1 = g*g; printf("#0159:%d:%d\t",n++,g1); g = g/g1; printf("#0161:%d:%d\t",n++,g); g = g-g1; printf("#0163:%d:%d\t",n++,g); g = sin(g1); printf("#0165:%d:%d\t",n++,g); g = testd(g,g1); printf("#0167:%d:%d\t",n++,g); printf("#0168:\n"); g = g+g; g = 3.0; printf("#0172:%d:%d\t",n++,g); g1 = g<<2; printf("#0174:<< %d:%d\t",n++,g1); g1 = g<<f; printf("#0176:<< %d:%d\t",n++,g1); g1 = g>>2; printf("#0178:>> %d:%d\t",n++,g1); g1 = g>>f; printf("#0180:>> %d:%d\t",n++,g1); g = g%g1; printf("#0182:%% %d:%d\t",n++,g); g = g|g1; printf("#0184:| %d:%d\t",n++,g); g = g&g1; printf("#0186:& %d:%d\t",n++,g); g = g^g1; printf("#0188:^ %d:%d\t",n++,g); g = -120; g1 = g>>2; printf("#0192:>> %d:%d\t",n++,g1); g1 = g>>f; printf("#0194:>> %d:%d\t",n++,g1); printf("#0196:\n"); printf("#0198:simple unsigned "); f = f+f; printf("#0200:%d:%d\t",n++,f); f1 = f*f; printf("#0202:%d:%d\t",n++,f1); f = f/f1; printf("#0204:%d:%d\t",n++,f); f = f-f1; printf("#0206:%d:%d\t",n++,f); f = sin(f1); printf("#0208:%d:%d\t",n++,f); printf("#0209:\n"); f = 3.0; printf("#0212:%d:%d\t",n++,f); f1 = f<<f; printf("#0214:%d:%d\t",n++,f1); f = f%f1; printf("#0216:%d:%d\t",n++,f); f = f|f1; printf("#0218:%d:%d\t",n++,f); f = f&f1; printf("#0220:%d:%d\t",n++,f); f = f^f1; printf("#0222:%d:%d\t",n++,f); printf("#0223:\n"); printf("#0226:post/pre increment "); g1 = g; printf("#0228:%d:%d\t",n++,g1++ - ++g); f1 = f; printf("#0231:%d:%d\t",n++,f1++ - ++f); g1 = g; printf("#0234:%d:%d\t",n++,g1-- - --g); f1 = f; printf("#0237:%d:%d\t",n++,f1-- - --f); printf("#0239:\n"); printf("#0240:simple calc "); f=3.13; g=-7.56; f1=-5.13; g1=7.56; g = f+f; printf("#0245:%d:%d\t",n++,g); f = g*g; printf("#0247:%d:%d\t",n++,f); g = g*g+f*f-g1*g1; printf("#0249:%d:%d\t",n++,g); printf("#0250:\n"); printf("#0252:unsigned argument "); f = testf(f,f1); printf("#0254:%d:%d\t",n++,f); printf("#0256:\nindirect "); n=1; f = 1.3; pf=&f; pf1=&f1; ahoaho(); g = 1.0; pg=&g; pg1=&g1; *pg = *pg+ *pg; printf("#0263:%d:%d\t",n++,*pg); *pg1 = *pg**pg; printf("#0265:%d:%d\t",n++,*pg1); *pg = *pg/ *pg1; printf("#0267:%d:%d\t",n++,*pg); *pg = *pg-*pg1; printf("#0269:%d:%d\t",n++,*pg); *pg = sin(*pg1); printf("#0271:%d:%d\t",n++,*pg); *pg = testd(*pg,*pg1); printf("#0273:%d:%d\t",n++,*pg); printf("#0274:\n"); *pf = *pf+*pf; printf("#0277:%d:%d\t",n++,*pf); *pf1 = *pf**pf; printf("#0279:%d:%d\t",n++,*pf1); *pf = *pf/ *pf1; printf("#0281:%d:%d\t",n++,*pf); *pf = *pf-*pf1; printf("#0283:%d:%d\t",n++,*pf); *pf = sin(*pf1); printf("#0285:%d:%d\t",n++,*pf); printf("#0286:\n"); printf("#0288:indirect post/pre "); *pg1 = *pg; printf("#0290:%d:%d\t",n++,(*pg1)++ - ++(*pg)); *pf1 = *pf; printf("#0293:%d:%d\t",n++,(*pf1)++ - ++(*pf)); *pg1 = *pg; printf("#0296:%d:%d\t",n++, (*pg1)-- - --(*pg)); *pf1 = *pf; printf("#0299:%d:%d\t",n++, (*pf1)-- - --(*pf)); printf("#0300:\n"); *pf=3.13; *pg=-7.56; *pf1=-5.13; *pg1=7.56; *pg = *pf+*pf; printf("#0305:%d:%d\t",n++,*pg); *pf = *pg**pg; printf("#0307:%d:%d\t",n++,*pf); *pg = *pg**pg+*pf**pf-*pg1**pg1; printf("#0309:%d:%d\t",n++,*pg); printf("#0310:\n"); printf("#0312:unsigned argument "); *pf = testf(*pf,*pf1); printf("#0315:%d:%d\t",n++,*pf); printf("#0318:\nassop "); n=1; f = 1.3; g = 1.0; g *= 2*g; printf("#0324:%d:%d\t",n++,g); g /= 2*g; printf("#0326:%d:%d\t",n++,g); g -= 2*g; printf("#0328:%d:%d\t",n++,g); g += 2*g; printf("#0330:%d:%d\t",n++,g); g = -3; f *= 2*g; printf("#0334:%d:%d\t",n++,f); f /= 2*g; printf("#0336:%d:%d\t",n++,f); f -= 2*g; printf("#0338:%d:%d\t",n++,f); f += 2*g; printf("#0340:%d:%d\t",n++,f); printf("#0341:\n"); n=1; f = 1.3; g = 1.0; printf("#0347:indirect assop "); *pg *= 2**pg; printf("#0349:%d:%d\t",n++,*pg); *pg /= 2**pg; printf("#0351:%d:%d\t",n++,*pg); *pg -= 2**pg; printf("#0353:%d:%d\t",n++,*pg); *pg += 2**pg; printf("#0355:%d:%d\t",n++,*pg); *pg = -3; *pf *= 2**pg; printf("#0359:%d:%d\t",n++,*pf); *pf /= 2**pg; printf("#0361:%d:%d\t",n++,*pf); *pf -= 2**pg; printf("#0363:%d:%d\t",n++,*pf); *pf += 2**pg; printf("#0365:%d:%d\t",n++,*pf); printf("#0366:\n"); return; } int test2(int f,int i) { int g,h,s; printf("#0377:rec: %d %d\n",i,f); if (i<=0) return f; g = f*2; h = f-3.5; #if 1 printf("#0382:rec: %d %d\n",i,f); s = f*1.5; printf("#0384: %d\n", s); s = test2(s,i-1); printf("#0386: %d\n", s); s = s/(h-1); printf("#0388: %d\n", s); printf("#0389: %d\n", (int)(h/3-(3.0-(g+3)*s/(h-1)))); #endif return h/3-(3.0-(g+3)*test2(f*1.5,i-1)/(h-1)); } int test3(int base,int base1) { int i,j; for(i=0;i<10;i++) { for(j=0;j<10;j++) { printf("#0400:%d ",(base+i)%(base1+j)); } printf("#0402:\n"); } return 0; }