view test/int.c @ 234:eccea7c904ee

float powerpc drexp done (?)
author kono
date Thu, 29 Apr 2004 19:40:43 +0900
parents 7bfc1435cdc6
children 0c256ea2a97e
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("%d %f %d %f\n",1,0.1,1,0.1);
   printf("%f %d %f %d\n",0.1,1,0.1,1);

   printf("%u %u %u\n",d00,d01%d02,d01*d02);

   g = 1;
   g = -g;
   printf("%d\ncond ",g);
   if(f==f*1) printf("1 ");
   if(d==f*1) printf("2 ");
   if(f==f1) printf("3 ");
   if(d==d1) printf("4 ");
   if(d==d2) printf("-4 ");
   if(d>d1) printf("5 ");
   if(d>d2) printf("-5 ");
   if(d>=d1) printf("6 ");
   if(d>=d2) printf("-6 ");
   if(d!=d1) printf("7 ");
   if(d!=d2) printf("-7 ");
   if(d<d1) printf("8 ");
   if(d<d2) printf("-8 ");
   if(d<=d1) printf("9 ");
   if(d<=d2) printf("-9 ");

   printf("unsigned ");
   if(f>f1) printf("5 ");
   if(f>f2) printf("-5 ");
   if(f>=f1) printf("6 ");
   if(f>=f2) printf("-6 ");
   if(f!=f1) printf("7 ");
   if(f!=f2) printf("-7 ");
   if(f<f1) printf("8 ");
   if(f<f2) printf("-8 ");
   if(f<=f1) printf("9 ");
   if(f<=f2) printf("-9 ");

   d = 123; f=-234;
   i = d;
   d = i;
   i = f;
   f = i;
   printf("\n%d %d %d",i,d,f);
   f = g = d = d1 = d2 = f;
   printf(" %d %d %d %d\n",i,d,f,g);

   d = 320967294; f=224967294;
   u = d;
   d = u;
   u = f;
   f = u;
   printf("%u %d %d\n",u,d,f);

   print(1.0);
   print(0.1234*100);
   print(1.234e6);
   print(-1.234e+3);

   test1();
   printf("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("f %d ",f);
    printf("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("simple int ");
    f = 1.3;

    g = 1.0;
    g = g+g;
    printf("%d:%d\t",n++,g);
    g1 = g*g;
    printf("%d:%d\t",n++,g1);
    g = g/g1;
    printf("%d:%d\t",n++,g);
    g = g-g1;
    printf("%d:%d\t",n++,g);
    g = sin(g1);
    printf("%d:%d\t",n++,g);
    g = testd(g,g1);
    printf("%d:%d\t",n++,g);
    printf("\n");
    g = g+g;

    g = 3.0;
    printf("%d:%d\t",n++,g);
    g1 = g<<2;
    printf("<< %d:%d\t",n++,g1);
    g1 = g<<f;
    printf("<< %d:%d\t",n++,g1);
    g1 = g>>2;
    printf(">> %d:%d\t",n++,g1);
    g1 = g>>f;
    printf(">> %d:%d\t",n++,g1);
    g = g%g1;
    printf("% %d:%d\t",n++,g);
    g = g|g1;
    printf("| %d:%d\t",n++,g);
    g = g&g1;
    printf("& %d:%d\t",n++,g);
    g = g^g1;
    printf("^ %d:%d\t",n++,g);

    g = -120;
    g1 = g>>2;
    printf(">> %d:%d\t",n++,g1);
    g1 = g>>f;
    printf(">> %d:%d\t",n++,g1);

    printf("\n");

    printf("simple unsigned ");
    f = f+f;
    printf("%d:%d\t",n++,f);
    f1 = f*f;
    printf("%d:%d\t",n++,f1);
    f = f/f1;
    printf("%d:%d\t",n++,f);
    f = f-f1;
    printf("%d:%d\t",n++,f);
    f = sin(f1);
    printf("%d:%d\t",n++,f);
    printf("\n");

    f = 3.0;
    printf("%d:%d\t",n++,f);
    f1 = f<<f;
    printf("%d:%d\t",n++,f1);
    f = f%f1;
    printf("%d:%d\t",n++,f);
    f = f|f1;
    printf("%d:%d\t",n++,f);
    f = f&f1;
    printf("%d:%d\t",n++,f);
    f = f^f1;
    printf("%d:%d\t",n++,f);
    printf("\n");


    printf("post/pre increment ");
    g1 = g;
    printf("%d:%d\t",n++,g1++ - ++g);

    f1 = f;
    printf("%d:%d\t",n++,f1++ - ++f);

    g1 = g;
    printf("%d:%d\t",n++,g1-- - --g);

    f1 = f;
    printf("%d:%d\t",n++,f1-- - --f);

    printf("\n");
    printf("simple calc ");

    f=3.13; g=-7.56; f1=-5.13; g1=7.56;

    g = f+f;
    printf("%d:%d\t",n++,g);
    f = g*g;
    printf("%d:%d\t",n++,f);
    g = g*g+f*f-g1*g1;
    printf("%d:%d\t",n++,g);
    printf("\n");

    printf("unsigned argument ");
    f = testf(f,f1);
    printf("%d:%d\t",n++,f);

    printf("\nindirect  ");
    n=1;
    f = 1.3; pf=&f; pf1=&f1;

    ahoaho();
    g = 1.0; pg=&g; pg1=&g1;
    *pg = *pg+ *pg;
    printf("%d:%d\t",n++,*pg);
    *pg1 = *pg**pg;
    printf("%d:%d\t",n++,*pg1);
    *pg = *pg/ *pg1;
    printf("%d:%d\t",n++,*pg);
    *pg = *pg-*pg1;
    printf("%d:%d\t",n++,*pg);
    *pg = sin(*pg1);
    printf("%d:%d\t",n++,*pg);
    *pg = testd(*pg,*pg1);
    printf("%d:%d\t",n++,*pg);
    printf("\n");

    *pf = *pf+*pf;
    printf("%d:%d\t",n++,*pf);
    *pf1 = *pf**pf;
    printf("%d:%d\t",n++,*pf1);
    *pf = *pf/ *pf1;
    printf("%d:%d\t",n++,*pf);
    *pf = *pf-*pf1;
    printf("%d:%d\t",n++,*pf);
    *pf = sin(*pf1);
    printf("%d:%d\t",n++,*pf);
    printf("\n");

    printf("indirect post/pre ");
    *pg1 = *pg;
    printf("%d:%d\t",n++,(*pg1)++ - ++(*pg));

    *pf1 = *pf;
    printf("%d:%d\t",n++,(*pf1)++ - ++(*pf));

    *pg1 = *pg;
    printf("%d:%d\t",n++, (*pg1)-- - --(*pg));

    *pf1 = *pf;
    printf("%d:%d\t",n++, (*pf1)-- - --(*pf));
    printf("\n");

    *pf=3.13; *pg=-7.56; *pf1=-5.13; *pg1=7.56;

    *pg = *pf+*pf;
    printf("%d:%d\t",n++,*pg);
    *pf = *pg**pg;
    printf("%d:%d\t",n++,*pf);
    *pg = *pg**pg+*pf**pf-*pg1**pg1;
    printf("%d:%d\t",n++,*pg);
    printf("\n");

    printf("unsigned argument ");

    *pf = testf(*pf,*pf1);
    printf("%d:%d\t",n++,*pf);


    printf("\nassop ");
    n=1;
    f = 1.3;
    g = 1.0;

    g *= 2*g;
    printf("%d:%d\t",n++,g);
    g /= 2*g;
    printf("%d:%d\t",n++,g);
    g -= 2*g;
    printf("%d:%d\t",n++,g);
    g += 2*g;
    printf("%d:%d\t",n++,g);

    g = -3;
    f *= 2*g;
    printf("%d:%d\t",n++,f);
    f /= 2*g;
    printf("%d:%d\t",n++,f);
    f -= 2*g;
    printf("%d:%d\t",n++,f);
    f += 2*g;
    printf("%d:%d\t",n++,f);
    printf("\n");

    n=1;
    f = 1.3;
    g = 1.0;

    printf("indirect assop ");
    *pg *= 2**pg;
    printf("%d:%d\t",n++,*pg);
    *pg /= 2**pg;
    printf("%d:%d\t",n++,*pg);
    *pg -= 2**pg;
    printf("%d:%d\t",n++,*pg);
    *pg += 2**pg;
    printf("%d:%d\t",n++,*pg);

    *pg = -3;
    *pf *= 2**pg;
    printf("%d:%d\t",n++,*pf);
    *pf /= 2**pg;
    printf("%d:%d\t",n++,*pf);
    *pf -= 2**pg;
    printf("%d:%d\t",n++,*pf);
    *pf += 2**pg;
    printf("%d:%d\t",n++,*pf);
    printf("\n");


    return;
}

int
test2(int f,int i)
{
    int g,h;
  
    if (i<=0) return f;
#if 0
    printf("rec: %d %d\n",i,f);
#endif
    g =  f*2;
    h =  f-3.5;
    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("%d ",(base+i)%(base1+j));
	}
	printf("\n");
    }
    return 0;
}