Exemplo n.º 1
0
void rotnumber(long double xi1, long double yi1, int time) {
    __float128 x = xi1;
    __float128 y = yi1;
    __float128 xn;
    __float128 yn;
    __float128 xav=0.Q;
    __float128 yav=0.Q;
    __float128 cosval=0.Q;
    __float128 dot, mo, mn, theta;
    __float128 rho=0.Q; 
    __float128 wsum=0.Q;
    for(int t=0; t< time; t++) {
        wsum+=weight((__float128)t/(__float128)time);
    }


    for(int t=0; t < time; t++) {
        xav+=x*weight((__float128)t/(__float128)time);
        yav+=y*weight((__float128)t/(__float128)time);
        xn = smod(x+y,2.Q*M_PIq);
        yn = smod(y+1.4Q*sinq(x+y),2.Q*M_PIq);
        x=xn;
        y=yn;
    }
    xav/=wsum;
    yav/=wsum;
    mn = sqrtq((x-xav)*(x-xav) + (y-yav)*(y-yav));
    for(int t=0; t< time; t++) {
        xn = smod(x+y,2.Q*M_PIq);
        yn = smod(y+1.4Q*sinq(x+y),2.Q*M_PIq);

        dot = (xn-xav)*(x-xav) + (yn-yav)*(y-yav);
        mo = mn;
        mn = sqrtq((xn-xav)*(xn-xav) + (yn-yav)*(yn-yav));
        cosval = dot/(mo*mn);
        theta = acosq(cosval);
        rho += theta*weight((__float128)t/(__float128)time);
        x=xn;
        y=yn;
    }
    rho/=wsum*2.Q*M_PIq;

    printf("The rotation number at (xi=%Lf, yi=%Lf) is %.20Lf\n",xi1,yi1,(long double)rho);
}
tFloat GaussSeidel::residual(tFloat *_x)
{
    // Residuo
    tFloat sum, res = 0.0q;
    for(tInteger i = 0; i<neqmax; i++){
        sum = b[i]-ax[i]*_x[i];
        for(tInteger j=0; j<neIndex[i]; j++)
            sum -= A[i][j]*_x[AIndex[i][j]];
        res += sum*sum;
    }

    return sqrtq(res);
}
Exemplo n.º 3
0
/* Square root algorithm from glibc.  */
__complex128
csqrtq (__complex128 z)
{
  __float128 re = REALPART(z), im = IMAGPART(z);
  __complex128 v;

  if (im == 0)
  {
    if (re < 0)
    {
      COMPLEX_ASSIGN (v, 0, copysignq (sqrtq (-re), im));
    }
    else
    {
      COMPLEX_ASSIGN (v, fabsq (sqrtq (re)), copysignq (0, im));
    }
  }
  else if (re == 0)
  {
    __float128 r = sqrtq (0.5 * fabsq (im));
    COMPLEX_ASSIGN (v, r, copysignq (r, im));
  }
  else
  {
    __float128 d = hypotq (re, im);
    __float128 r, s;

    /* Use the identity   2  Re res  Im res = Im x
	to avoid cancellation error in  d +/- Re x.  */
    if (re > 0)
      r = sqrtq (0.5 * d + 0.5 * re), s = (0.5 * im) / r;
    else
      s = sqrtq (0.5 * d - 0.5 * re), r = fabsq ((0.5 * im) / s);

    COMPLEX_ASSIGN (v, r, copysignq (s, im));
  }
  return v;
}
Exemplo n.º 4
0
bool is_prime(long long int x) {
	long long int root = sqrtq(x);
	long long int i;

	if(x == 2) {
		return 1;
	}

	for(i = 3; i < root; i += 2) {
		if(x % i ==0) {
			return 0;
		}
	}
	return 1;

}
Exemplo n.º 5
0
 inline __float128 abs( std::complex< __float128 > x )
 {
     return sqrtq( x.real() * x.real() + x.imag() * x.imag() );
 }
Exemplo n.º 6
0
 inline __float128 sqrt( __float128 x )
 {
     return sqrtq( x );
 }
Exemplo n.º 7
0
inline void eval_sqrt(float128_backend& result, const float128_backend& arg)
{
   result.value() = sqrtq(arg.value());
}
Exemplo n.º 8
0
void curve_convergence(long double ax1, long double ay1, long double bx1, long double by1, long double anonlin, int numpoints, int time, int fnum, int preshift, double (*points)[2]) {

    FILE *f;

    const char name[] = "outputs/text_quasi_curve_t%u_np%u_ax%.2Lf_ay%.2Lf_bx%.2Lf_by%.2Lf.txt";
    char fname[100];
    sprintf(fname, name, time,numpoints,ax1,ay1,bx1,by1);
    f= fopen(fname,"w");

    int t, v;
    __float128 wsum=0;
    for(t=0; t<time; t++) {
        wsum += weight((__float128)t/(__float128)time);
    }

    __float128 ax = ax1;
    __float128 bx = bx1;
    __float128 ay = ay1;
    __float128 by = by1;

    __float128 x,y, xn, yn;
    __float128 first[fnum];
    __float128 second[fnum];
    __float128 diff[fnum];
    __float128 diff_mag;
    __float128 numzeros;
    __float128 wvar;

    __float128 nonlin=anonlin;
    
    for(int p=0; p < numpoints; p++) {
        x = ax + (bx-ax)*((__float128)p/(__float128)numpoints);
        y = ay + (by-ay)*((__float128)p/(__float128)numpoints);
        fprintf(f,"x: %.10Lf, y: %.10Lf, ", (long double)x, (long double)y);
        for(int s=0; s < preshift; s++) {
            for(t=0; t< time; t++) {
                xn = smod(x+y,2.Q*M_PIq);
                yn = smod(nonlin*sinq(x+y)+y,2.Q*M_PIq);
                x = xn;
                y = yn;
            }
        }

        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(nonlin*sinq(x+y)+y,2.Q*M_PIq);
            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(nonlin*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 = (__float128)(-1.Q*log10q(diff_mag));
        fprintf(f,"numzeros: %.12Lf\n",(long double)numzeros);
        points[p][0] = (double)p/(__float128)numpoints;
        points[p][1] = (double)numzeros;
        printf("numzeros: %.20Lf\n",(long double)numzeros);
    }

}
Exemplo n.º 9
0
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]);
}
Exemplo n.º 10
0
inline Quad Sqrt( const Quad& alpha ) { return sqrtq(alpha); }
Exemplo n.º 11
0
Arquivo: hypotq.c Projeto: 0day-ci/gcc
__float128
hypotq (__float128 x, __float128 y)
{
  __float128 a, b, t1, t2, y1, y2, w;
  int64_t j, k, ha, hb;

  GET_FLT128_MSW64(ha,x);
  ha &= 0x7fffffffffffffffLL;
  GET_FLT128_MSW64(hb,y);
  hb &= 0x7fffffffffffffffLL;
  if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
  SET_FLT128_MSW64(a,ha);	/* a <- |a| */
  SET_FLT128_MSW64(b,hb);	/* b <- |b| */
  if((ha-hb)>0x78000000000000LL) {return a+b;} /* x/y > 2**120 */
  k=0;
  if(ha > 0x5f3f000000000000LL) {	/* a>2**8000 */
     if(ha >= 0x7fff000000000000LL) {	/* Inf or NaN */
         uint64_t low;
         w = a+b;			/* for sNaN */
         GET_FLT128_LSW64(low,a);
         if(((ha&0xffffffffffffLL)|low)==0) w = a;
         GET_FLT128_LSW64(low,b);
         if(((hb^0x7fff000000000000LL)|low)==0) w = b;
         return w;
     }
     /* scale a and b by 2**-9600 */
     ha -= 0x2580000000000000LL;
     hb -= 0x2580000000000000LL;	k += 9600;
     SET_FLT128_MSW64(a,ha);
     SET_FLT128_MSW64(b,hb);
  }
  if(hb < 0x20bf000000000000LL) {	/* b < 2**-8000 */
      if(hb <= 0x0000ffffffffffffLL) {	/* subnormal b or 0 */
          uint64_t low;
  	GET_FLT128_LSW64(low,b);
  	if((hb|low)==0) return a;
  	t1=0;
  	SET_FLT128_MSW64(t1,0x7ffd000000000000LL); /* t1=2^16382 */
  	b *= t1;
  	a *= t1;
  	k -= 16382;
      } else {		/* scale a and b by 2^9600 */
          ha += 0x2580000000000000LL; 	/* a *= 2^9600 */
  	hb += 0x2580000000000000LL;	/* b *= 2^9600 */
  	k -= 9600;
  	SET_FLT128_MSW64(a,ha);
  	SET_FLT128_MSW64(b,hb);
      }
  }
    /* medium size a and b */
  w = a-b;
  if (w>b) {
      t1 = 0;
      SET_FLT128_MSW64(t1,ha);
      t2 = a-t1;
      w  = sqrtq(t1*t1-(b*(-b)-t2*(a+t1)));
  } else {
      a  = a+a;
      y1 = 0;
      SET_FLT128_MSW64(y1,hb);
      y2 = b - y1;
      t1 = 0;
      SET_FLT128_MSW64(t1,ha+0x0001000000000000LL);
      t2 = a - t1;
      w  = sqrtq(t1*y1-(w*(-w)-(t1*y2+t2*b)));
  }
  if(k!=0) {
      uint64_t high;
      t1 = 1.0Q;
      GET_FLT128_MSW64(high,t1);
      SET_FLT128_MSW64(t1,high+(k<<48));
      return t1*w;
  } else return w;
}