view test/float.c @ 895:e9ba80b0827d

ato mou sukoshi...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 06 Apr 2014 17:11:44 +0900
parents fcb642ef08c9
children
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("#0055:%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("#0061:%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("#0067:%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("#0073:%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("#0079:%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("#0091:%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("#0102:%d\ncond0 ",1);
   if(f==f*1.0) printf("#0103:t ");
   printf("#0104:%d\ncond1 ",f==f*1.0);
   if(d==f*1.0) printf("#0105:t ");
   printf("#0106:%d\ncond2 ",d==f*1.0);
   if(f==f1) printf("#0107:t ");
   printf("#0108:%d\ncond3 ",f==f1);
   if(d==d1) printf("#0109:t ");
   printf("#0110:%d\ncond4 ",d==d2);
   if(d==d2) printf("#0111:t ");
   printf("#0112:%d\ncond5 ",(d==d2));
   if(d>d1) printf("#0113:t ");
   printf("#0114:%d\ncond6 ",d>d1);
   if(d>d2) printf("#0115:t ");
   printf("#0116:%d\ncond7 ",d>d2);
   if(d>=d1) printf("#0117:t ");
   printf("#0118:%d\ncond8 ",d>=d1);
   if(d>=d2) printf("#0119:t ");
   printf("#0120:%d\ncond9 ",d>=d2);
   if(d!=d1) printf("#0121:t ");
   printf("#0122:%d\ncond10 ",d!=d1);
   if(d!=d2) printf("#0123:5 ");
   printf("#0124:%d\ncond11 ",d!=d2);
   if(d<d1) printf("#0125:t ");
   printf("#0126:%d\ncond12 ",d<d1);
   if(d<d2) printf("#0127:t ");
   printf("#0128:%d\ncond13 ",d<d2);
   if(d<=d1) printf("#0129:t ");
   printf("#0130:%d\ncond14 ",d<=d1);
   if(d<=d2) printf("#0131:t ");
   printf("#0132:%d\ncond15 ",d<=d2);
   d = 123.4234; f=-234.333;
   i = d;
   d = i;
   i = f;
   f = i;
   printf("#0138:\ni=%d d=%g f=%f",i,d,f);
   f = g = d = d1 = d2 = f;
   printf("#0140: i=%d d=%g f=%f g=%g\n",i,d,f,g);

   d = 4204967294.4234; f=4204967294.4234;
   u = d;
   printf("#0144:1: u=%u d=%g f=%f\n",u,d,f);
   d = u;
   printf("#0146:2: u=%u d=%g f=%f\n",u,d,f);
   u = f;
   printf("#0148:3: u=%u d=%g f=%f\n",u,d,f);
   f = u;
   printf("#0150: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("#0158: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("#0171:d %g ",d);
    printf("#0172:dx %08x %08x\n",*(dd),*(dd+1));

    dd = (int*) &f;
    printf("#0175:f %g ",f);
    printf("#0176: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("#0204:simple double ");
    f = 1.3;

    g = 1.0;
    g = g+g;
    printf("#0209:%d:%g\n",n++,g);
    g1 = g*g;
    printf("#0211:%d:%g\n",n++,g1);
    g = g/g1;
    printf("#0213:%d:%g\n",n++,g);
    g = g-g1;
    printf("#0215:%d:%g\n",n++,g);
    g = sin(g1);
    printf("#0217:%d:%g\n",n++,g);
    g = testd(g,g1);
    printf("#0219:%d:%g\n",n++,g);
    printf("#0220:\n");

    printf("#0222:simple float ");
    f = f+f;
    printf("#0224:%d:%g\n",n++,f);
    f1 = f*f;
    printf("#0226:%d:%g\n",n++,f1);
    f = f/f1;
    printf("#0228:%d:%g\n",n++,f);
    f = f-f1;
    printf("#0230:%d:%g\n",n++,f);
    f = sin(f1);
    printf("#0232:%d:%g\n",n++,f);
    printf("#0233:\n");

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

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

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

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

    printf("#0248:\n");
    printf("#0249:simple calc ");

    f=0.13; g=-0.56; f1=-0.13; g1=0.56;

    g = f+f;
    printf("#0254:%d:%g\n",n++,g);
    f = g*g;
    printf("#0256:%d:%g\n",n++,f);
    g = g*g+f*f-g1*g1;
    printf("#0258:%d:%g\n",n++,g);
    printf("#0259:\n");

    printf("#0261:float argument ");
    f = testf(f,f1);
    printf("#0263:%d:%g\n",n++,f);

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

    g = 1.0; pg=&g; pg1=&g1;
    *pg = *pg+ *pg;
    printf("#0271:%d:%g\n",n++,*pg);
    *pg1 = *pg**pg;
    printf("#0273:%d:%g\n",n++,*pg1);
    *pg = *pg/ *pg1;
    printf("#0275:%d:%g\n",n++,*pg);
    *pg = *pg-*pg1;
    printf("#0277:%d:%g\n",n++,*pg);
    *pg = sin(*pg1);
    printf("#0279:%d:%g\n",n++,*pg);
    *pg = testd(*pg,*pg1);
    printf("#0281:%d:%g\n",n++,*pg);
    printf("#0282:\n");

    *pf = *pf+*pf;
    printf("#0285:%d:%g\n",n++,*pf);
    *pf1 = *pf**pf;
    printf("#0287:%d:%g\n",n++,*pf1);
    *pf = *pf/ *pf1;
    printf("#0289:%d:%g\n",n++,*pf);
    *pf = *pf-*pf1;
    printf("#0291:%d:%g\n",n++,*pf);
    *pf = sin(*pf1);
    printf("#0293:%d:%g\n",n++,*pf);
    printf("#0294:\n");

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

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

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

    *pf1 = *pf;
    printf("#0307:%d:%g\n",n++, (*pf1)-- - --(*pf));
    printf("#0308:\n");

    *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56;

    *pg = *pf+*pf;
    printf("#0313:%d:%g\n",n++,*pg);
    *pf = *pg**pg;
    printf("#0315:%d:%g\n",n++,*pf);
    *pg = *pg**pg+*pf**pf-*pg1**pg1;
    printf("#0317:%d:%g\n",n++,*pg);
    printf("#0318:\n");

    printf("#0320:float argument ");

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


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

    g *= 2*g;
    printf("#0332:%d:%g\n",n++,g);
    g /= 2*g;
    printf("#0334:%d:%g\n",n++,g);
    g -= 2*g;
    printf("#0336:%d:%g\n",n++,g);
    g += 2*g;
    printf("#0338:%d:%g\n",n++,g);

    f *= 2*g;
    printf("#0341:%d:%g\n",n++,f);
    f /= 2*g;
    printf("#0343:%d:%g\n",n++,f);
    f -= 2*g;
    printf("#0345:%d:%g\n",n++,f);
    f += 2*g;
    printf("#0347:%d:%g\n",n++,f);
    printf("#0348:\n");

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

    printf("#0354:indirect assop ");
    *pg *= 2**pg;
    printf("#0356:%d:%g\n",n++,*pg);
    *pg /= 2**pg;
    printf("#0358:%d:%g\n",n++,*pg);
    *pg -= 2**pg;
    printf("#0360:%d:%g\n",n++,*pg);
    *pg += 2**pg;
    printf("#0362:%d:%g\n",n++,*pg);

    *pf *= 2**pg;
    printf("#0365:%d:%g\n",n++,*pf);
    *pf /= 2**pg;
    printf("#0367:%d:%g\n",n++,*pf);
    *pf -= 2**pg;
    printf("#0369:%d:%g\n",n++,*pf);
    *pf += 2**pg;
    printf("#0371:%d:%g\n",n++,*pf);
    printf("#0372:\n");


    return;
}

double
test9(double f,int i)
{
    double g,h;
  
    if (i<=0) return f;
#if 1
    printf("#0385: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("#0419: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);
}