view test/float.c @ 479:51c1b795b4f3

fix broken $gp in jal in code segement
author kono
date Sat, 26 Nov 2005 09:50:55 +0900
parents f8ba383dbc39
children a379da780856
line wrap: on
line source

#include "stdio.h"

void test8();
void print(double d);

extern double sin(double);
// extern float fsin(float);
double test9(double f,int i);
int test7();

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;
}

void
test1(float id, float x,float y,float sx,float sy,int behav)
{
    printf("%f %f %f %f %f %d\n", id,x,y,sx,sy,behav);
}

void
test2(int id, int x,float y,float sx,float sy,int behav)
{
    printf("%d %d %f %f %f %d\n", id,x,y,sx,sy,behav);
}

void
test3(int id, float x,float y,float sx,float sy,int behav)
{
    printf("%d %f %f %f %f %d\n", id,x,y,sx,sy,behav);
}

void
test4(int id, float x,int y,float sx,float sy,int behav)
{
    printf("%d %f %d %f %f %d\n", id,x,y,sx,sy,behav);
}

void
test5(float id, int x,float y,int sx,float sy,int behav)
{
    printf("%f %d %f %d %f %d\n", id,x,y,sx,sy,behav);
}



int
main(int ac,char *av[]) {
   double g;
   int i;
   unsigned u;
   double d00 = ac?0.5:3;

   printf("#0058:%g\n",d00);

    test1(1,2,3,10,11,4);
    test2(1,2,3,10,11,4);
    test3(1,2,3,10,11,4);
    test4(1,2,3,10,11,4);
    test5(1,2,3,10,11,4);
    test7();

   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);

   test8();
   printf("#0118:nested call: %g\n",test9(test9(test9(test9(-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
test8()
{
    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
test9(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)*test9(f*0.5,i-1)/(h-1));
}

struct huga0 {
    char c;
    short s;
    int i;
    long l;
    float f;
};
struct huga {
    char c;
    short s;
    int i;
    long l;
    float f;
    struct huga0 hh;
};


struct enemy{
    int charno;                 // image number
    float x;                    // x location
    float y;                    // y location
    int ap;                     // armor point
};

void
print_param(struct enemy *e)
{
    printf("charno:%d   x,y:%f,%f   hp:%d\n",
           e->charno,e->x,e->y,e->ap);
}


int test7()
{
    struct huga h;
    struct enemy e;

    h.c = 10;
    h.s = 20;
    h.i = 30;
    h.l = 40;
    h.f = 50;
    h.hh.c = 10;
    h.hh.s = 20;
    h.hh.i = 30;
    h.hh.l = 40;
    h.hh.f = 50;


    e.charno=5; e.x=50.0; e.y=30.0; e.ap=100;
    print_param(&e);
    return (0);
}