inline void eval_floor(float128_backend& result, const float128_backend& arg) { result.value() = floorq(arg.value()); }
inline Quad Floor( const Quad& alpha ) { return floorq(alpha); }
void convergence(int rows, int cols, int time, long double aleastx, long double aleasty, long double adeltax, long double adeltay, int fnum, char (*m)[cols]) { printf("Running Optimized Version of Quasiperiodicity\n"); unsigned int i, j, t, v; FILE *f; const char name[] = "outputs/text_optquasi_conv_t%u_g%u_xs%.2Lf_ys%.2Lf_xb%.2Lf_yb%.2Lf.txt"; char fname[100]; sprintf(fname, name, time,rows, aleastx, aleasty, aleastx+rows*adeltax,aleasty+cols*adeltay); f= fopen(fname,"w"); fprintf(f,"ONLY BOX IS CERTAIN\n\n"); unsigned int** traj = (unsigned int**) malloc(sizeof(unsigned int*)*time); int ntraj=0; for(int o=0; o < time; o++) { traj[o] = (unsigned int*) malloc(sizeof(unsigned int)*2); } __float128 wsum=0; for(t=0; t<time; t++) { wsum += weight((__float128)t/(__float128)time); } __float128 x,y, xn, yn; __float128 first[fnum]; __float128 second[fnum]; __float128 diff[fnum]; __float128 diff_mag; char numzeros; __float128 wvar; __float128 leastx = aleastx; __float128 leasty = aleasty; __float128 deltax = adeltax; __float128 deltay = adeltay; for(i=0; i < rows; i++) { printf("i is: %u\n", i); for(j=0; j < cols; j++) { if(m[i][j]==-1) { ntraj++; x = leastx + j*deltax+0.5*deltax; y = leasty + i*deltay+0.5*deltay; memset(first, 0, sizeof(__float128)*fnum); for( t=0; t<time; t++) { wvar = weight((__float128)t/(__float128)time); for(v=0; v<fnum;v++) { first[v] += (*fvec[v])(x,y)*wvar; } xn = smod(x+y,2.Q*M_PIq); yn = smod(1.4Q*sinq(x+y)+y,2.Q*M_PIq); traj[t][0] = floorq((x-leastx)/deltax); traj[t][1] = floorq((y-leasty)/deltay); x = xn; y = yn; } memset(second,0,sizeof(__float128)*fnum); for( t=0; t <time; t++) { wvar = weight((__float128)t/(__float128)time); for(v=0; v<fnum;v++) { second[v]+= (*fvec[v])(x,y)*wvar; } xn = smod(x+y,2.Q*M_PIq); yn = smod(1.4Q*sinq(x+y)+y,2.Q*M_PIq); x = xn; y = yn; } diff_mag=0.Q; for(v=0; v<fnum; v++) { diff[v]=(second[v]-first[v])/wsum; diff_mag+=diff[v]*diff[v]; } diff_mag = sqrtq(diff_mag); numzeros = (char)(-1.Q*log10q(diff_mag)); for(t=0;t<time;t++) { m[(int)fmin(fmax(traj[t][1],0),rows-1)][(int)fmin(fmax(traj[t][0],0),cols-1)] = numzeros; } //m[i][j]=(unsigned char)numzeros; (old way) } } } for(int o=0; o< time; o++) { free(traj[o]); } free(traj); for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { fprintf(f, "m[%u][%u] is %d",i,j,m[i][j]); } } printf("%u\n",m[8][8]); }
__float128 expm1q (__float128 x) { __float128 px, qx, xx; int32_t ix, sign; ieee854_float128 u; int k; /* Detect infinity and NaN. */ u.value = x; ix = u.words32.w0; sign = ix & 0x80000000; ix &= 0x7fffffff; if (!sign && ix >= 0x40060000) { /* If num is positive and exp >= 6 use plain exp. */ return expq (x); } if (ix >= 0x7fff0000) { /* Infinity. */ if (((ix & 0xffff) | u.words32.w1 | u.words32.w2 | u.words32.w3) == 0) { if (sign) return -1.0Q; else return x; } /* NaN. No invalid exception. */ return x; } /* expm1(+- 0) = +- 0. */ if ((ix == 0) && (u.words32.w1 | u.words32.w2 | u.words32.w3) == 0) return x; /* Overflow. */ if (x > maxlog) { errno = ERANGE; return (HUGE_VALQ * HUGE_VALQ); } /* Minimum value. */ if (x < minarg) return (4.0/HUGE_VALQ - 1.0Q); /* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */ xx = C1 + C2; /* ln 2. */ px = floorq (0.5 + x / xx); k = px; /* remainder times ln 2 */ x -= px * C1; x -= px * C2; /* Approximate exp(remainder ln 2). */ px = (((((((P7 * x + P6) * x + P5) * x + P4) * x + P3) * x + P2) * x + P1) * x + P0) * x; qx = (((((((x + Q7) * x + Q6) * x + Q5) * x + Q4) * x + Q3) * x + Q2) * x + Q1) * x + Q0; xx = x * x; qx = x + (0.5 * xx + xx * px / qx); /* exp(x) = exp(k ln 2) exp(remainder ln 2) = 2^k exp(remainder ln 2). We have qx = exp(remainder ln 2) - 1, so exp(x) - 1 = 2^k (qx + 1) - 1 = 2^k qx + 2^k - 1. */ px = ldexpq (1.0Q, k); x = px * qx + (px - 1.0); return x; }