Mercurial > hg > CbC > old > device
view test/float.c @ 427:0c256ea2a97e
Bitfield left value for ia32
author | kono |
---|---|
date | Sat, 30 Oct 2004 18:49:25 +0900 |
parents | c7abd48191b3 |
children | cfa4db8b18a5 |
line wrap: on
line source
#include "stdio.h" void test1(); void print(double d); extern double sin(double); // extern float fsin(float); double test2(double f,int i); float f = 0.3; double d = 0.3; float f1 = 0.3; double d1 = 0.3; double d2 = -0.2; float h = 1.0; int d2i(double d) { return (int)d; } double i2d(int u) { return (double)u; } unsigned u; unsigned d2u(double d) { return (unsigned)d; } double u2d(unsigned u) { return (double)u; } double f2d(float u) { double u1; u1 = f1; return (double)u; } float d2f(double u) { float u1; u1 = d1; return (float)u; } int main(int ac,char *av[]) { double g; int i; unsigned u; double d00 = ac?0.5:3; printf("#0058:%g\n",d00); g = 1.0; g = -g; printf("#0062:%d\ncond0 ",1); if(f==f*1.0) printf("#0063:t "); printf("#0064:%d\ncond1 ",f==f*1.0); if(d==f*1.0) printf("#0065:t "); printf("#0066:%d\ncond2 ",d==f*1.0); if(f==f1) printf("#0067:t "); printf("#0068:%d\ncond3 ",f==f1); if(d==d1) printf("#0069:t "); printf("#0070:%d\ncond4 ",d==d2); if(d==d2) printf("#0071:t "); printf("#0072:%d\ncond5 ",(d==d2)); if(d>d1) printf("#0073:t "); printf("#0074:%d\ncond6 ",d>d1); if(d>d2) printf("#0075:t "); printf("#0076:%d\ncond7 ",d>d2); if(d>=d1) printf("#0077:t "); printf("#0078:%d\ncond8 ",d>=d1); if(d>=d2) printf("#0079:t "); printf("#0080:%d\ncond9 ",d>=d2); if(d!=d1) printf("#0081:t "); printf("#0082:%d\ncond10 ",d!=d1); if(d!=d2) printf("#0083:5 "); printf("#0084:%d\ncond11 ",d!=d2); if(d<d1) printf("#0085:t "); printf("#0086:%d\ncond12 ",d<d1); if(d<d2) printf("#0087:t "); printf("#0088:%d\ncond13 ",d<d2); if(d<=d1) printf("#0089:t "); printf("#0090:%d\ncond14 ",d<=d1); if(d<=d2) printf("#0091:t "); printf("#0092:%d\ncond15 ",d<=d2); d = 123.4234; f=-234.333; i = d; d = i; i = f; f = i; printf("#0098:\ni=%d d=%g f=%f",i,d,f); f = g = d = d1 = d2 = f; printf("#0100: i=%d d=%g f=%f g=%g\n",i,d,f,g); d = 4204967294.4234; f=4204967294.4234; u = d; printf("#0104:1: u=%u d=%g f=%f\n",u,d,f); d = u; printf("#0106:2: u=%u d=%g f=%f\n",u,d,f); u = f; printf("#0108:3: u=%u d=%g f=%f\n",u,d,f); f = u; printf("#0110:4: u=%u d=%g f=%f\n",u,d,f); print(1.0); print(0.1234); print(1.234e10); print(1.234e-10); test1(); printf("#0118:nested call: %g\n",test2(test2(test2(test2(-0.333,3),5),6),7)); return 0; } void print(double d) { float f; int *dd; f = d; dd = (int*) &d; printf("#0131:d %g ",d); printf("#0132:dx %08x %08x\n",*(dd),*(dd+1)); dd = (int*) &f; printf("#0135:f %g ",f); printf("#0136:dx %08x \n",*(dd)); } double testd(double i,double j) { return j+1.1+.0e3+12.3e-12; } float testf(float i,float j) { return j+1; } void test1() { float f; float f1; double g; double g1; float *pf; float *pf1; double *pg; double *pg1; int n = 1; printf("#0164:simple double "); f = 1.3; g = 1.0; g = g+g; printf("#0169:%d:%g\t",n++,g); g1 = g*g; printf("#0171:%d:%g\t",n++,g1); g = g/g1; printf("#0173:%d:%g\t",n++,g); g = g-g1; printf("#0175:%d:%g\t",n++,g); g = sin(g1); printf("#0177:%d:%g\t",n++,g); g = testd(g,g1); printf("#0179:%d:%g\t",n++,g); printf("#0180:\n"); printf("#0182:simple float "); f = f+f; printf("#0184:%d:%g\t",n++,f); f1 = f*f; printf("#0186:%d:%g\t",n++,f1); f = f/f1; printf("#0188:%d:%g\t",n++,f); f = f-f1; printf("#0190:%d:%g\t",n++,f); f = sin(f1); printf("#0192:%d:%g\t",n++,f); printf("#0193:\n"); printf("#0195:post/pre increment "); g1 = g; printf("#0197:%d:%g\t",n++,g1++ - ++g); f1 = f; printf("#0200:%d:%g\t",n++,f1++ - ++f); g1 = g; printf("#0203:%d:%g\t",n++,g1-- - --g); f1 = f; printf("#0206:%d:%g\t",n++,f1-- - --f); printf("#0208:\n"); printf("#0209:simple calc "); f=0.13; g=-0.56; f1=-0.13; g1=0.56; g = f+f; printf("#0214:%d:%g\t",n++,g); f = g*g; printf("#0216:%d:%g\t",n++,f); g = g*g+f*f-g1*g1; printf("#0218:%d:%g\t",n++,g); printf("#0219:\n"); printf("#0221:float argument "); f = testf(f,f1); printf("#0223:%d:%g\t",n++,f); printf("#0225:\nindirect "); n=1; f = 1.3; pf=&f; pf1=&f1; g = 1.0; pg=&g; pg1=&g1; *pg = *pg+ *pg; printf("#0231:%d:%g\t",n++,*pg); *pg1 = *pg**pg; printf("#0233:%d:%g\t",n++,*pg1); *pg = *pg/ *pg1; printf("#0235:%d:%g\t",n++,*pg); *pg = *pg-*pg1; printf("#0237:%d:%g\t",n++,*pg); *pg = sin(*pg1); printf("#0239:%d:%g\t",n++,*pg); *pg = testd(*pg,*pg1); printf("#0241:%d:%g\t",n++,*pg); printf("#0242:\n"); *pf = *pf+*pf; printf("#0245:%d:%g\t",n++,*pf); *pf1 = *pf**pf; printf("#0247:%d:%g\t",n++,*pf1); *pf = *pf/ *pf1; printf("#0249:%d:%g\t",n++,*pf); *pf = *pf-*pf1; printf("#0251:%d:%g\t",n++,*pf); *pf = sin(*pf1); printf("#0253:%d:%g\t",n++,*pf); printf("#0254:\n"); printf("#0256:indirect post/pre "); *pg1 = *pg; printf("#0258:%d:%g\t",n++,(*pg1)++ - ++(*pg)); *pf1 = *pf; printf("#0261:%d:%g\t",n++,(*pf1)++ - ++(*pf)); *pg1 = *pg; printf("#0264:%d:%g\t",n++, (*pg1)-- - --(*pg)); *pf1 = *pf; printf("#0267:%d:%g\t",n++, (*pf1)-- - --(*pf)); printf("#0268:\n"); *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56; *pg = *pf+*pf; printf("#0273:%d:%g\t",n++,*pg); *pf = *pg**pg; printf("#0275:%d:%g\t",n++,*pf); *pg = *pg**pg+*pf**pf-*pg1**pg1; printf("#0277:%d:%g\t",n++,*pg); printf("#0278:\n"); printf("#0280:float argument "); *pf = testf(*pf,*pf1); printf("#0283:%d:%g\t",n++,*pf); printf("#0286:\nassop "); n=1; f = 1.3; g = 1.0; g *= 2*g; printf("#0292:%d:%g\t",n++,g); g /= 2*g; printf("#0294:%d:%g\t",n++,g); g -= 2*g; printf("#0296:%d:%g\t",n++,g); g += 2*g; printf("#0298:%d:%g\t",n++,g); f *= 2*g; printf("#0301:%d:%g\t",n++,f); f /= 2*g; printf("#0303:%d:%g\t",n++,f); f -= 2*g; printf("#0305:%d:%g\t",n++,f); f += 2*g; printf("#0307:%d:%g\t",n++,f); printf("#0308:\n"); n=1; f = 1.3; g = 1.0; printf("#0314:indirect assop "); *pg *= 2**pg; printf("#0316:%d:%g\t",n++,*pg); *pg /= 2**pg; printf("#0318:%d:%g\t",n++,*pg); *pg -= 2**pg; printf("#0320:%d:%g\t",n++,*pg); *pg += 2**pg; printf("#0322:%d:%g\t",n++,*pg); *pf *= 2**pg; printf("#0325:%d:%g\t",n++,*pf); *pf /= 2**pg; printf("#0327:%d:%g\t",n++,*pf); *pf -= 2**pg; printf("#0329:%d:%g\t",n++,*pf); *pf += 2**pg; printf("#0331:%d:%g\t",n++,*pf); printf("#0332:\n"); return; } double test2(double f,int i) { double g,h; if (i<=0) return f; #if 1 printf("#0345:rec: %d %g\n",i,f); #endif g = f*2; h = f-0.5; return h/3-(3.0-(g+3)*test2(f*0.5,i-1)/(h-1)); }