void RebWindowManager::DestroyWindow(std::string name) { DisableRender(name); SDL_DestroyWindow(windows[name]); windows.erase(name); if(finv(name) != -1) keys.erase(keys.begin() + finv(name)); }
int check_float( float a, float b ) { uint32_t a_int = getUint32_t( a ); uint32_t b_int = getUint32_t( b ); float normal_f = (float)sqrt( a ); uint32_t sqrt = getUint32_t( normal_f ); uint32_t f_sqrt = fsqrt( a_int ); if ( sqrt != f_sqrt ) { printf("数字 : %f\n", a); printf("通常 %x\n", sqrt ); printf("自作 %x\n", f_sqrt ); } uint32_t inv = getUint32_t( (float)(1.0 / a ) ); uint32_t f_inv = finv( a_int ); uint32_t div = getUint32_t( (float)(1.0 / b ) ); uint32_t f_div = finv( b_int ); return sqrt == f_sqrt && inv == f_inv && div == f_div; }
void print_finv( uint32_t a ) { uint32_t b = finv( a ); float af = getFloat(a); float bf = getFloat(b); printf("実装したfinv\n"); printf("小数表示 finv( %f ) = %f\n", af, bf ); printf("10進数表示 finv( %d ) = %d\n", a, b ); printf("16進数表示 finv( %x ) = %x\n", a, b ); }
double *mlpg(PStream * pst) { int doupdate(PStream *, int); void calc_pi(PStream *, int); void calc_k(PStream *, int); void update_P(PStream *, int); void update_c(PStream *, int); int tcur, tmin, tmax; int d, m, u; pst->sm.t++; tcur = pst->sm.t & pst->sm.mask; tmin = (pst->sm.t - pst->range) & pst->sm.mask; tmax = (pst->sm.t + pst->dw.maxw[WRIGHT]) & pst->sm.mask; for (u = -pst->range * 2; u <= pst->range * 2; u++) { for (m = 0; m <= pst->order; m++) pst->sm.P[u][tmax][m] = 0.0; } for (m = 0; m < pst->vSize; m++) { pst->sm.mseq[tmax][m] = pst->mean[m]; pst->sm.ivseq[tmax][m] = pst->ivar[m]; } for (m = 0; m <= pst->order; m++) { if (pst->iType != 2) pst->sm.c[tmax][m] = pst->mean[m]; else pst->sm.c[tmax][m] = pst->mean[m] * finv(pst->ivar[m]); pst->sm.P[0][tmax][m] = finv(pst->ivar[m]); } for (d = 1; d < pst->dw.num; d++) { if (doupdate(pst, d)) { calc_pi(pst, d); calc_k(pst, d); update_P(pst, d); update_c(pst, d); } } pst->par = pst->sm.c[tmin]; return (pst->par); }
int main(int argc, char*argv[]){ uint32_t i,j; uint32_t result; uint32_t out; int k=0; int del = 0; int table[128]; i=0; while(i<128){ table[i]=0; i++; } //j=9; //while(j<1024){ j=0; k=0; i = (127 << 23) + (j << 13); while(k < 8192*1024){ result=finv_s(i); out = finv(i,0); del = out - result; table[del+64] = table[del+64]+1; k++; i++; } /*if(table[69]){ i=0; while(i<128){ table[i]=0; i++; } k=0; i = (127 << 23) + (j << 13); while(k < 8192){ result=finv_s(i); out = finv(i,0); del = out - result; table[del+64] = table[del+64]+1; k++; i++; } printf("offset=%d\n",j); printtable(table); return 1; } j++; }*/ printtable(table); return 0; }
int main(void) { FILE *fp; union data_32bit a, n, result, correct; char a_str[33]; int count_mistake = 0; //誤答数をカウント int count_1bit_diff = 0; //1bitずれをカウント memset(a_str, '\0', 33); if ((fp = fopen("testcase.txt", "r")) == NULL) { printf("file open error.\n"); exit(EXIT_FAILURE); } while(fscanf(fp, "%s", a_str) != EOF) { a.uint32 = str_to_uint32t(a_str); n.uint32 = normalize(a.uint32); result.uint32 = finv(a.uint32); correct.fl32 = 1.0 / n.fl32; //非正規仮数を0に潰す if (n.uint32 != a.uint32 && count_mistake <= 10) { //printf("normalized!!!!!\n"); //debug } if (equal(result.uint32, correct.uint32) == 1) { //何もしない } else if (equal(result.uint32, correct.uint32) == 2) { count_1bit_diff++; //show_testcase(a, result, correct); } else { //printf("0\n"); //一致しなければ0 count_mistake++; if (count_mistake <= 5) { show_testcase(a, result, correct); } if (count_mistake == 5) { printf("more than 5 mistakes.\n"); } } memset(a_str, '\0', 33); } printf("total ~%dbit_diff : %d\n", PERMIT, count_1bit_diff); printf("total mistakes : %d\n", count_mistake); fclose(fp); return 0; }
/* the gateway function */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mwSize nzS, n; nzS = mxGetM(prhs[1]); /* create matrix */ n = mxGetN(prhs[0]); plhs[0] = mxCreateSparse(n,n, nzS, mxREAL); /* input parameters are L, irS and jcS */ finv(plhs[0],prhs[0],mxGetPr(prhs[1]),mxGetPr(prhs[2])); }
void update_c(PStream * pst, int d) { int j, m, u; double *mean, *ivar, x; ivar = pst->sm.ivseq[pst->sm.t & pst->sm.mask] + (pst->order + 1) * d; mean = pst->sm.mseq[pst->sm.t & pst->sm.mask] + (pst->order + 1) * d; for (m = 0; m <= pst->order; m++) { x = mean[m]; if (pst->iType == 2) x *= finv(ivar[m]); for (j = pst->dw.width[d][WLEFT]; j <= pst->dw.width[d][WRIGHT]; j++) x -= pst->dw.coef[d][j] * pst->sm.c[(pst->sm.t + j) & pst->sm.mask][m]; for (u = -pst->range; u <= pst->dw.maxw[WRIGHT]; u++) pst->sm.c[(pst->sm.t + u) & pst->sm.mask][m] += pst->sm.k[u][m] * x; } return; }
int main(int argc, char*argv[]){ int failed=0; uint32_t i; uint32_t result; uint32_t out; int aaa[1024]; int k=0; int m=0; int del = 0; int table[128]; if(argc < 4){ printf("few args!!\n"); return 1; } i=0; while(i<128){ table[i]=0; i++; } int offset = atoi(argv[1]); int offset_term = atoi(argv[2]); i=(127<<23) + (offset << 13); int j=0 - (atoi(argv[3])); int dist=1000; int best=0; while(offset < offset_term){ dist=1000; j=0 - (atoi(argv[3])); while(j < atoi(argv[3]) + 1){ k=0; i=(127<<23) + (offset << 13); while(k < 8192*1024){ result=finv_s(i); out = finv(i,j); del = out - result; /*if(del > 4 || del < -4){ printf("offset: %d\n",offset); printf("del: %d\n",del); printbin(i); printbin(out); printbin(result); return 0; }*/ table[del+64] = table[del+64]+1; k++; i++; } printtable(table); return 1; if(distri(table) < dist){ best = j; dist = distri(table); } m=0; while(m<128){ table[m]=0; m++; } j++; } k=0; i=(127<<23) + (offset << 13); while(k < 8192){ result=finv_s(i); out = finv(i,best); del = out - result; table[del+64] = table[del+64]+1; k++; i++; } //print23bin(ctou(dummy[offset])); //printtable(table); //printf("%d\n",lub(table)); aaa[offset] = 0 - ((lub(table)+glb(table)) /2); /*m=0; while(m<128){ table[m]=0; m++; }*/ if(dist < 10){ fprintf(stderr,"clear: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table)); }else{ fprintf(stderr,"FAILED...: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table)); failed++; } fprintf(stderr,"sinchoku...%d/%d\n",offset-atoi(argv[1]),atoi(argv[2])-atoi(argv[1])); incdecprint2(dummy2,best,offset); m=0; while(m<128){ table[m]=0; m++; } offset++; } offset=atoi(argv[1]); while(offset < atoi(argv[2])){ incdecprint(dummy,aaa[offset],offset); offset++; } //printf("best case: %d dist: %d\n",best,dist); fprintf(stderr,"failed cases: %d/%d\n",failed,atoi(argv[2])-atoi(argv[1])); return 0; }
int main(int argc, char **argv) { FILE *pdffp = stdin, *parfp = stdout; int nframe, delay; char *coef; int coeflen; PStream pst; int i, j; void InitPStream(PStream *); double *mlpg(PStream *); pst.order = ORDER; pst.range = RANGE; pst.iType = ITYPE; pst.dw.fn = (char **) calloc(sizeof(char *), argc); pst.dw.num = 1; pst.dw.calccoef = -1; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) { if (**++argv == '-') { switch (*(*argv + 1)) { case 'd': if (pst.dw.calccoef == 1) { fprintf(stderr, "%s : Options '-r' and '-d' should not be defined simultaneously!\n", cmnd); return (1); } pst.dw.calccoef = 0; if (isfloat(*++argv)) { coeflen = 0; for (i = 0; (i < argc - 1) && isfloat(argv[i]); i++) { coeflen += strlen(argv[i]) + 1; } coeflen += 1; coef = pst.dw.fn[pst.dw.num] = getmem(coeflen, sizeof(char)); for (j = 0; j < i; j++) { sprintf(coef, " %s", *argv); coef += strlen(*argv) + 1; if (j < i - 1) { argv++; argc--; } } } else { pst.dw.fn[pst.dw.num] = *argv; } pst.dw.num++; --argc; break; case 'r': if (pst.dw.calccoef == 0) { fprintf(stderr, "%s : Options '-r' and '-d' should not be defined simultaneously!\n", cmnd); return (1); } pst.dw.calccoef = 1; coeflen = atoi(*++argv); --argc; if ((coeflen != 1) && (coeflen != 2)) { fprintf(stderr, "%s : Number of delta parameter should be 1 or 2!\n", cmnd); return (1); } if (argc <= 1) { fprintf(stderr, "%s : Window size for delta parameter required!\n", cmnd); return (1); } pst.dw.fn[pst.dw.num] = *++argv; pst.dw.num++; --argc; if (coeflen == 2) { if (argc <= 1) { fprintf(stderr, "%s : Window size for delta-delta parameter required!\n", cmnd); return (1); } pst.dw.fn[pst.dw.num] = *++argv; pst.dw.num++; --argc; } break; case 'm': pst.order = atoi(*++argv); --argc; break; case 'l': pst.order = atoi(*++argv) - 1; --argc; break; case 'i': pst.iType = atoi(*++argv); --argc; break; case 's': pst.range = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else pdffp = getfp(*argv, "rb"); } InitPStream(&pst); delay = pst.range + pst.dw.maxw[WRIGHT]; nframe = 0; while (freadf(pst.mean, sizeof(*(pst.mean)), pst.vSize * 2, pdffp) == pst.vSize * 2) { if (pst.dw.num == 1) fwritef(pst.mean, sizeof(*pst.mean), pst.order + 1, parfp); else { if (pst.iType == 0) for (i = 0; i < pst.vSize; i++) pst.ivar[i] = finv(pst.ivar[i]); mlpg(&pst); if (nframe >= delay) fwritef(pst.par, sizeof(*(pst.par)), pst.order + 1, parfp); } nframe++; } if (pst.dw.num > 1) { for (i = 0; i < pst.vSize; i++) { pst.mean[i] = 0.0; pst.ivar[i] = 0.0; } for (i = 0; i < min(nframe, delay); i++) { mlpg(&pst); fwritef(pst.par, sizeof(*(pst.par)), pst.order + 1, parfp); } } return (0); }
int main(void) { union data_32bit a, n, result, correct; uint32_t i; long unsigned int total_mistakes = 0; //誤答数をカウント /* long unsigned int count_no_diff = 0; long unsigned int count_1ulp_diff = 0; //1bitずれをカウント long unsigned int count_2ulp_diff = 0; long unsigned int count_3ulp_diff = 0; */ long unsigned int count_total_diff[PERMIT+1]; int count, j; for (i = 0; i < PERMIT+1; i++) { count_total_diff[i] = 0; } for (i = 0; i < 4294967295; i++) { if ((i % 100000000) == 0) { printf("> checked (%2u/42)\n", i / 100000000); } a.uint32 = i; n.uint32 = normalize(i); result.uint32 = finv(a.uint32); correct.fl32 = 1.0 / n.fl32; //非正規仮数を0に潰す count = count_diff(result.uint32, correct.uint32); if (count < PERMIT+1) { count_total_diff[count]++; } else { if (total_mistakes <= 5) { show_testcase(a, result, correct); } total_mistakes++; } /* switch (count_diff(result.uint32, correct.uint32)) { case 0: count_no_diff++; break; case 1: count_1ulp_diff++; break; case 2: count_2ulp_diff++; break; case 3: count_3ulp_diff++; break; default: total_mistakes++; if (total_mistakes <= 5) { show_testcase(a, result, correct); } if (total_mistakes == 5) { printf("more than 5 mistakes.\n"); } break; } */ } /* printf("total no diff : %lu\n", count_no_diff); printf("total 1ulp diff : %lu\n", count_1ulp_diff); printf("total 2ulp diff : %lu\n", count_2ulp_diff); printf("total 3ulp diff : %lu\n", count_3ulp_diff); printf("total mistakes : %lu (more than 3ulp)\n", total_mistakes); */ for (j = 0; j < PERMIT+1; j++) { printf("total %dulp diff : %lu\n", j, count_total_diff[j]); } printf("total mistakes : %lu\n", total_mistakes); return 0; }