Exemplo n.º 1
0
 void Index::bound(int image_dims) {
     
     this->p[X] = min2(max2(this->p[X], 0), image_dims);
     this->p[Y] = min2(max2(this->p[Y], 0), image_dims);
     this->p[Z] = min2(max2(this->p[Z], 0), image_dims);
     
 }
Exemplo n.º 2
0
void render_set_clipbox(double x1,double y1,double x2,double y2)

    {
    _oldclipbox = (*clipbox);
    clipbox->p[0] = p2d_point(min2(x1,x2),min2(y1,y2));
    clipbox->p[1] = p2d_point(max2(x1,x2),max2(y1,y2));
    }
void set_variables(controlVariables &cv){
	alpha=cv.value_int("alpha");
	num_freqs=cv.value_int("num_freqs");
	d=cv.value_double("d");
	h_PML=cv.value_double("h_PML");
	h_sep=cv.value_double("h_sep");
	freq_min=cv.value_double("freq_min");
	freq_max=cv.value_double("freq_max");
	res=cv.value_double("res");
	duration_factor=cv.value_double("duration_factor");
	theta_degrees=cv.value_double("theta_degrees");
	angle_res_degrees=cv.value_double("angle_res_degrees");
	file_name_prefix=cv.value_special("file_name_prefix");

	size_x=(double) alpha;
	size_y=2*h_PML+d+5*h_sep;
	freq_centre=0.5*(max2(freq_min,freq_max)+min2(freq_min,freq_max));
	pw_freq_width=max2(freq_min,freq_max)-min2(freq_min,freq_max);

	int file_name_prefix_len=string(cv.value_special("file_name_prefix")).length();
	eps_file_name=new char[file_name_prefix_len+6];
	strcpy(eps_file_name,"eps__");
	strcat(eps_file_name,cv.value_special("file_name_prefix"));
	flux_file_name=new char[file_name_prefix_len+7];
	strcpy(flux_file_name,"flux__");
	strcat(flux_file_name,cv.value_special("file_name_prefix"));
}
Exemplo n.º 4
0
/*
 * pos_text: If the position of the given text is less than
 * passed in and the text hasn't already been distributed, adjust the value
 * of the passed in parameter.  Also set the width/height if smaller.
 * If dir == 0, handle horizontal, otherwise vertical.
 */
static Boolean
pos_text (F_text *t, int *min, int *size, int dir)
{
  int center, dum;

  text_bound (t, &llx, &lly, &urx, &ury,
	      &dum,&dum,&dum,&dum,&dum,&dum,&dum,&dum);
  if (dir == 0) {
    if (cur_halign == ALIGN_DISTRIB_C)
      center = (urx + llx)/2;
    else
      center = min2(urx, llx);
  } else {
    if (cur_valign == ALIGN_DISTRIB_C)
      center = (ury + lly)/2;
    else
      center = min2(ury, lly);
  }

  if ( (center < *min) && (t->distrib == 0) ) {
    *min = center;
    if (dir == 0)
      *size = abs(urx - llx);
    else
      *size = abs(ury - lly);
    return True;
  } else
    return False;
} /* pos_text */
int main()
{
   int n,m;
   while((scanf("%d %d",&n,&m))==2)
   {
       int i,j,A[105][105],S[105][105]={0};
       for(i=0;i<n;++i)
       {
           for(j=0;j<m;++j)
           {
               scanf("%d",&A[i][j]);
               if(i==0)
                   S[i][j]=A[i][j];
               else if(i!=0&&j==0)
                    S[i][j]=A[i][j]+min2(S[i-1][j+1],S[i-1][j]);
               else if(i!=0&&j==m-1)
                    S[i][j]=A[i][j]+min2(S[i-1][j-1],S[i-1][j]);
               else
                    S[i][j]=A[i][j]+min3(S[i-1][j-1],S[i-1][j],S[i-1][j+1]);
           }
       }
       i=n-1;
       int min=S[i][0];
       for(j=1;j<m;++j)
        min=min2(min,S[i][j]);
       printf("%d\n",min);
   }
    return 0;
}
Exemplo n.º 6
0
/*
 * pos_compound: If the position of the given compound is less
 * than passed in and the compound hasn't already been distributed, adjust the
 * value of the passed in parameter.  Also set the width/height if smaller.
 * If dir == 0, handle horizontal, otherwise vertical.
 */
static Boolean
pos_compound (F_compound *c, int *min, int *size, int dir)
{
  int center;

  compound_bound (c, &llx, &lly, &urx, &ury);
  if (dir == 0) {
    if (cur_halign == ALIGN_DISTRIB_C)
      center = (urx + llx)/2;
    else
      center = min2(urx, llx);
  } else {
    if (cur_valign == ALIGN_DISTRIB_C)
      center = (ury + lly)/2;
    else
      center = min2(ury, lly);
  }

  if ( (center < *min) && (c->distrib == 0) ) {
    *min = center;
    if (dir == 0)
      *size = abs(urx - llx);
    else
      *size = abs(ury - lly);
    return True;
  } else
    return False;
} /* pos_compound */
Exemplo n.º 7
0
// Fills the cost matrix, *cost, with respect to Sakoe & Chiba band constraint |i-j| < ks  -- O(k*n)
void
fill_cost_matrix_with_sakoe_chiba_constraint(const double *x, const double *y, int n, int m, int n_dimensions, int distance_selector,
                                             double warping_penalty,
                                             double *cost,
                                             int sakoe_chiba_band_parameter)
{
      double (*dist)(const double *,  const double *, const int);
      dist = distance_function(distance_selector);

      int i, j;

      // Fill cost matrix with infinities first
      for (i = 0; i < n*m; i++)
          cost[i] = INFINITY;

      // Initialise
      cost[0] = (*dist)(&x[0], &y[0], n_dimensions);

      for (i=1; i<min2(n, sakoe_chiba_band_parameter+1); i++)
          cost[i*m] = (*dist)(&x[i*n_dimensions], &y[0], n_dimensions) + cost[(i-1)*m] + warping_penalty;
      for (j=1; j<min2(m, sakoe_chiba_band_parameter+1); j++)
          cost[j] = (*dist)(&x[0], &y[j*n_dimensions], n_dimensions) + cost[(j-1)] + warping_penalty;

      // Fill only the columns that satisfy |i-j| <= sakoe_chiba_band_parameter
      for (i=1; i<n; i++)
        for (j=max2(i-sakoe_chiba_band_parameter, 1); j<min2(m, i+sakoe_chiba_band_parameter+1); j++)
             cost[i*m+j] = (*dist)(&x[i*n_dimensions], &y[j*n_dimensions], n_dimensions) +
    	        min3(cost[(i-1)*m+j] + warping_penalty, cost[(i-1)*m+(j-1)], cost[i*m+(j-1)] + warping_penalty);
}
void sampler_stochastic::get(double *p, int i, int j,
                       const double *a, const double *b,
                       const double *c, const double *d)
{
    int k = 0, n = point.get_n(i, j);

    double min[3] = { 1, 1, 1 };
    double max[3] = { 0, 0, 0 };

    double t[3];

    p[0] = 0;
    p[1] = 0;
    p[2] = 0;

    // Accumulate the first few samples and note the extremes.

    while (k < 8)
    {
        get(t, i, j, k, a, b, c, d);

        min[0] = min2(min[0], t[0]);
        min[1] = min2(min[1], t[1]);
        min[2] = min2(min[2], t[2]);

        max[0] = max2(max[0], t[0]);
        max[1] = max2(max[1], t[1]);
        max[2] = max2(max[2], t[2]);

        p[0] += t[0];
        p[1] += t[1];
        p[2] += t[2];

        k++;
    }

    // If the contrast exceeds the limit, accumulate the remaining samples.

    if (0.4 < (max[0] - min[0]) / (max[0] + min[0]) ||
        0.3 < (max[1] - min[1]) / (max[1] + min[1]) ||
        0.6 < (max[2] - min[2]) / (max[2] + min[2]))

        while (k < n)
        {
            get(t, i, j, k, a, b, c, d);

            p[0] += t[0];
            p[1] += t[1];
            p[2] += t[2];

            k++;
        }

    // Average the accumulated samples.

    p[0] /= k;
    p[1] /= k;
    p[2] /= k;
}
Exemplo n.º 9
0
Box3d :: Box3d (const Point3d& p1, const Point3d& p2)
{
  minx[0] = min2 (p1.X(), p2.X());
  minx[1] = min2 (p1.Y(), p2.Y());
  minx[2] = min2 (p1.Z(), p2.Z());
  maxx[0] = max2 (p1.X(), p2.X());
  maxx[1] = max2 (p1.Y(), p2.Y());
  maxx[2] = max2 (p1.Z(), p2.Z());
}
Exemplo n.º 10
0
/* show running transfers in detail */
void dinoex_dcld(const userinput *const u)
{
  fetch_curl_t *ft;
  fetch_queue_t *fq;
  char *effective_url;
  double dl_total;
  double dl_size;
  double dl_speed;
  double dl_time;
  int progress;
  int started;
  int left;

  updatecontext();
  for (ft = irlist_get_head(&fetch_trans); ft; ft = irlist_get_next(ft)) {
    dl_size = 0.0;
    curl_easy_getinfo(ft->curlhandle, CURLINFO_SIZE_DOWNLOAD, &dl_size);

    dl_total = 0.0;
    curl_easy_getinfo(ft->curlhandle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &dl_total);

    dl_speed = 0.0;
    curl_easy_getinfo(ft->curlhandle, CURLINFO_SPEED_DOWNLOAD, &dl_speed);

    dl_time = 0.0;
    curl_easy_getinfo(ft->curlhandle, CURLINFO_TOTAL_TIME, &dl_time);

    effective_url = NULL;
    curl_easy_getinfo(ft->curlhandle, CURLINFO_EFFECTIVE_URL, &effective_url);

    started = min2(359999, gdata.curtime - ft->starttime);
    left = min2(359999, (dl_total - dl_size) /
                        ((int)(max2(dl_speed, 1))));
    progress = ((dl_size + 50) * 100) / max2(dl_total, 1);
    a_respond(u, "   %2i  fetch       %-32s   Receiving %d%%", ft->id, ft->name, progress);
    a_respond(u, "                   %s", effective_url ? effective_url : ft->url);
    a_respond(u, "  ^- %5.1fK/s    %6" LLPRINTFMT "dK/%6" LLPRINTFMT "dK  %2i%c%02i%c/%2i%c%02i%c",
                (float)(dl_speed/1024),
                (ir_int64)(dl_size/1024),
                (ir_int64)(dl_total/1024),
                started < 3600 ? started/60 : started/60/60 ,
                started < 3600 ? 'm' : 'h',
                started < 3600 ? started%60 : (started/60)%60 ,
                started < 3600 ? 's' : 'm',
                left < 3600 ? left/60 : left/60/60 ,
                left < 3600 ? 'm' : 'h',
                left < 3600 ? left%60 : (left/60)%60 ,
                left < 3600 ? 's' : 'm');
  }

  updatecontext();
  progress = 0;
  for (fq = irlist_get_head(&gdata.fetch_queue); fq; fq = irlist_get_next(fq)) {
    a_respond(u, "   %2i  fetch       %-32s   Waiting", ++progress, fq->name);
    a_respond(u, "                   %s", fq->url);
  }
}
Exemplo n.º 11
0
 void INDEX_4Q :: Sort ()
 {
   if (min2 (i[1], i[2]) < min2 (i[0], i[3]))
     { Swap (i[0], i[1]); Swap (i[2], i[3]);}
   if (i[3] < i[0])
     { Swap (i[0], i[3]); Swap (i[1], i[2]);}
   if (i[3] < i[1])
     { Swap (i[1], i[3]); }
 }
Exemplo n.º 12
0
void
elastic_box(int x1, int y1, int x2, int y2)
{
    int		    wid, ht;

    set_line_stuff(1, RUBBER_LINE, 0.0, JOIN_MITER, CAP_BUTT,
		INV_PAINT, DEFAULT);
    wid = abs(x2-x1)+1;
    ht = abs(y2-y1)+1;
    zXDrawRectangle(tool_d, canvas_win, gccache[INV_PAINT],min2(x1,x2),min2(y1,y2),wid,ht);
}
Exemplo n.º 13
0
const Box3d& Box3d :: operator+=(const Box3d& b)
{
  minx[0] = min2 (minx[0], b.minx[0]);
  minx[1] = min2 (minx[1], b.minx[1]);
  minx[2] = min2 (minx[2], b.minx[2]);
  maxx[0] = max2 (maxx[0], b.maxx[0]);
  maxx[1] = max2 (maxx[1], b.maxx[1]);
  maxx[2] = max2 (maxx[2], b.maxx[2]);

  return *this;
}
Exemplo n.º 14
0
void Box3dSphere :: CalcDiamCenter ()
{
  diam = sqrt( sqr (maxx[0] - minx[0]) +
	       sqr (maxx[1] - minx[1]) + 
	       sqr (maxx[2] - minx[2]));
  
  c.X() = 0.5 * (minx[0] + maxx[0]);
  c.Y() = 0.5 * (minx[1] + maxx[1]);
  c.Z() = 0.5 * (minx[2] + maxx[2]);
  
  inner = min2 ( min2 (maxx[0] - minx[0], maxx[1] - minx[1]), maxx[2] - minx[2]) / 2;
}
Exemplo n.º 15
0
/* ******************************************************************************** */
void getCauchyPoint(double *CauchyPoint, double **Hes, double *Grad, double delta, 
		    int numSS) {
  /*
   Computes the Cauchy point using the formulas 4.7 and 4.8 in Nocedal
   and Wright, Numerical Optimization (1999), page 70.

   Note that because the Hessian is symmetric that it is equal to its
   transpose.
  */

  int i; // Counters
  double coeff; // Coefficient on gradient for Cauchy point
  double tau; // Multiplier used in Cauchy point calculation
  double normGrad; // ||Grad||
  double *Hgrad; // Hessian dotted with the gradient
  double numerator;   // Used to hold temporary variables
  double denominator;
  
  Hgrad = (double *) malloc (numSS * sizeof(double));

  normGrad = norm(Grad,numSS);
  MatrixVectorMult(Hgrad,Hes,Grad,numSS);
  numerator = pow(normGrad,3);
  denominator = delta * dot(Grad,Hgrad,numSS);
  tau = min2(numerator/denominator , 1.0);
  coeff = -tau * delta / normGrad;

  for (i = 0; i < numSS; i++) {
    CauchyPoint[i] = coeff*Grad[i];
  }
   
  free(Hgrad);

}
Exemplo n.º 16
0
int main()
{
	int l;
	while(scanf("%d",&l)!=EOF&&l)
	{
		int n;
		scanf("%d",&n);
		int i,j,k,a[60];
		int kx[60][60][60];	//kx[i][j][k]表示在 a[i]和a[k]之间切短a[j] i<j<k 
		for(i=1;i<=n;i++)scanf("%d",&a[i]);
		a[0]=0;
		a[n+1]=l;
		for(i=0;i<=n+1;i++)for(j=i+1;j<=n+1;j++)for(k=j+1;k<=n+1;k++)kx[i][j][k]=a[k]-a[i];
		int dp[60][60];		//dp[i][j]表示把a[i]和a[j]之间所有的都切掉所能达到的最小花费 
		i=0;
		for(j=0;j<=n+1-i;j++)dp[j][j+i]=0;
		i=1;
		for(j=0;j<=n+1-i;j++)dp[j][j+i]=0;
		for(i=2;i<=n+1;i++)
		{
			for(j=0;j<=n+1-i;j++)
			{
				//目标dp[j][j+i]=min(dp[j,k]+dp[k,i+j]+kx[i,k,i+j])
				int min=2147483630;
				for(k=j+1;k<=j+i-1;k++)min=min2(min,dp[j][k]+dp[k][i+j]+kx[j][k][i+j]);
				dp[j][j+i]=min;
				}
			}
	//	for(i=n+1;i>=0;i--){for(j=0;j<=n+1;j++)printf("%6d",dp[i][j]);printf("\n");}
		printf("The minimum cutting is %d.\n",dp[0][n+1]);
		}
	return 0;
	}
Exemplo n.º 17
0
// addiert zwei Polynome
int *polynom_addierer(int *ergebnis_poly, int *poly1, int *poly2, int *grad_ergebnis, int grad1, int grad2)
{
    int i, grad_max, grad_min;
    if(grad1==grad2)
    {
        grad_min = grad_max = grad1;
    }
    else
    {
        grad_max = max2(grad1, grad2);
        grad_min = min2(grad1, grad2);
    }
    *grad_ergebnis=grad_max;
    ergebnis_poly = (int *) calloc(*grad_ergebnis, sizeof(int));
    for(i=0;i<=grad_min;i++)
    {
        ergebnis_poly[i]=poly1[i]+poly2[i];
    }
    if(grad1==grad2)
        ;
    else if (grad1>grad2)
        for(;i<=grad_max;i++)
            ergebnis_poly[i]=poly1[i];
    else if (grad1<grad2)
        for(;i<=grad_max;i++)
            ergebnis_poly[i]=poly2[i];
    else
        return 0;
    return (ergebnis_poly);
}
Exemplo n.º 18
0
int main()
{
	int x = 19;
	int y = 20;
	printf("%d\n",min(x,y));
	min2(x,y);
}
Exemplo n.º 19
0
static void
tag_region(int x, int y)
{
    int		    xmin, ymin, xmax, ymax;

    elastic_box(fix_x, fix_y, cur_x, cur_y);
    /* erase last lengths if appres.showlengths is true */
    erase_box_lengths();
    xmin = min2(fix_x, x);
    ymin = min2(fix_y, y);
    xmax = max2(fix_x, x);
    ymax = max2(fix_y, y);
    tag_obj_in_region(xmin, ymin, xmax, ymax);
    compound_selected();
    draw_mousefun_canvas();
}
Exemplo n.º 20
0
/*
  send_string -- send string to socket.
*/
void
send_string (int s, const char *msg)
{
#if 0
  if (send(s,msg,strlen(msg),0) < 0) {
    perror(progname);
    fprintf(stderr,"%s: unable to send\n",progname);
    exit(1);
  }; /* if */ 
#else  
  int len, left=strlen(msg);
  while (left > 0) {
    if ((len=write(s,msg,min2(left,GSERV_BUFSZ))) < 0) {
       /* XEmacs addition: [email protected] */
       if (errno == EPIPE) {
 	return ;
       }
      perror(progname);
      fprintf(stderr,"%s: unable to send\n",progname);
      exit(1);
    }; /* if */
    left -= len;
    msg += len;
  }; /* while */ 
#endif
} /* send_string */
Exemplo n.º 21
0
void Vector :: ChangeLength (INDEX alength)
{
  (*mycout) << "Vector::ChangeLength called" << endl;
  if (length == alength) return;
  
  if (alength == 0)
    {
      //    delete [] data;
      DeleteDouble (length, data);
      length = 0;
      return;
    }
  
  double * olddata = data;

  data = NewDouble (alength);
  //  data = new double[alength];
  if (!data)
    {
    length = 0;
    (*myerr) << "Vector::SetLength: Vector not allocated" << endl;
    delete [] olddata;
    }

  memcpy (data, olddata, min2(alength, length));

  delete [] olddata;
  length = alength;
  }
Exemplo n.º 22
0
void Clock::displayColor(bool onOff)
{
     Digit hour1(x, y), hour2(x, y+10), min1(x, y+25), min2(x, y+35), sec1(x, y+50), sec2(x, y+60);
     hour1.changeColor(true); 
     hour2.changeColor(true); 
     min1.changeColor(true); 
     min2.changeColor(true); 
     sec1.changeColor(true); 
     sec2.changeColor(true); 
     if(onOff)
     {
          clearDisplay();
          hour1.display(hr/10, true); 
          hour2.display(hr%10, true);
          min1.display(min/10, true);
          min2.display(min%10, true); 
          sec1.display(sec/10, isSec);
          sec2.display(sec%10, isSec);

          if(isPM)
          {
             attron(COLOR_PAIR(BLACKONYELLOW));
             mvprintw(x+6, y-5, "PM");
             attroff(COLOR_PAIR(BLACKONYELLOW));
          }
          else
          {
             attron(COLOR_PAIR(WHITEONBLACK));
             mvprintw(x+6, y-5, "  ");
          }
          refresh();
     }
     else
         clearDisplay();   
}
Exemplo n.º 23
0
int main()
{
    char a=min1('z','b');
    std::cout<<a<<"\n";
    int b=min2(1,8);
    std::cout<<b;
}
Exemplo n.º 24
0
  int AdFront2 :: AddLine (int pi1, int pi2,
                           const PointGeomInfo & gi1, const PointGeomInfo & gi2)
  {
    int minfn;
    int li;

    FrontPoint2 & p1 = points[pi1];
    FrontPoint2 & p2 = points[pi2];


    nfl++;

    p1.AddLine();
    p2.AddLine();

    minfn = min2 (p1.FrontNr(), p2.FrontNr());
    p1.DecFrontNr (minfn+1);
    p2.DecFrontNr (minfn+1);

    if (dellinel.Size() != 0)
      {
	li = dellinel.Last();
	dellinel.DeleteLast ();
	lines[li] = FrontLine (INDEX_2(pi1, pi2));
      }
    else
      {
	li = lines.Append(FrontLine (INDEX_2(pi1, pi2))) - 1;
      }

  
    if (!gi1.trignum || !gi2.trignum)
      {
	cout << "ERROR: in AdFront::AddLine, illegal geominfo" << endl;
      }
  
    lines[li].SetGeomInfo (gi1, gi2);

    Box3d lbox;
    lbox.SetPoint(p1.P());
    lbox.AddPoint(p2.P());

    linesearchtree.Insert (lbox.PMin(), lbox.PMax(), li);

    if (allflines)
      {
	if (allflines->Used (INDEX_2 (GetGlobalIndex (pi1), 
				      GetGlobalIndex (pi2))))
	  {
	    cerr << "ERROR Adfront2::AddLine: line exists" << endl;
	    (*testout) << "ERROR Adfront2::AddLine: line exists" << endl;
	  }

	allflines->Set (INDEX_2 (GetGlobalIndex (pi1), 
				 GetGlobalIndex (pi2)), 1);
      }

    return li;
  }
Exemplo n.º 25
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main()
{
//   min1(foo{}, foo{}); // error - invalid operands to <
   min1(10, 20);
   
//   min2(foo{}, foo{}); // no matching function min2
   min2(10, 20);
}
Exemplo n.º 26
0
bool MCRenderer::connectRays(Path& path, int connectIndex, bool merged)
{
	Ray& lightRay = path[connectIndex];
	Ray& eyeRay = path[connectIndex+1];

	if(!merged && (lightRay.directionSampleType == Ray::DEFINITE || eyeRay.directionSampleType == Ray::DEFINITE))
		return false;

	if (merged && eyeRay.directionSampleType == Ray::DEFINITE)
		return false;

	const Ray& prevLightRay = path[max2(connectIndex - 1, 0)];
	const Ray& prevEyeRay = path[min2((connectIndex + 2), path.size()-1)];
	lightRay.direction = eyeRay.origin - lightRay.origin;
	lightRay.direction.normalize();
	eyeRay.direction = -lightRay.direction;

	if(!merged)
	{
		lightRay.directionProb = 1;
		lightRay.color = prevLightRay.getBSDF(lightRay);
		lightRay.directionSampleType = Ray::RANDOM;
		if(lightRay.contactObject && connectIndex > 0)
		{
			if(lightRay.getContactNormal().dot(lightRay.direction) <= 0)
			{
				lightRay.insideObject = lightRay.contactObject;
			}
			else
			{
				if(lightRay.getContactNormal().dot(prevLightRay.direction) <= 0)
					lightRay.insideObject = prevLightRay.insideObject;
				else
					lightRay.insideObject = renderer->scene.findInsideObject(lightRay, lightRay.contactObject);
			}
		}
	}

	eyeRay.directionProb = 1;
	eyeRay.color = prevEyeRay.getBSDF(eyeRay);
	eyeRay.directionSampleType = Ray::RANDOM;
	if(eyeRay.contactObject && connectIndex < path.size()-2)
	{
		if(eyeRay.getContactNormal().dot(eyeRay.direction) <= 0)
		{
			eyeRay.insideObject = eyeRay.contactObject;
		}
		else
		{
			if(eyeRay.getContactNormal().dot(prevEyeRay.direction) <= 0)
				eyeRay.insideObject = prevEyeRay.insideObject;
			else
				eyeRay.insideObject = renderer->scene.findInsideObject(eyeRay, eyeRay.contactObject);
		}
	}
	return true;
}
Exemplo n.º 27
0
/*
  handle_response -- accept a response from stdin (the gnu process) and pass the
                     information on to the relevant client.
*/
static void
handle_response (void)
{
  char buf[GSERV_BUFSZ+1];
  int offset=0;
  int s;
  int len = 0;
  int result_len;

  /* read in "n/m:" (n=client fd, m=message length) */
  while (offset < GSERV_BUFSZ &&
	 ((len = read(0,buf+offset,1)) > 0) &&
	 buf[offset] != ':') {
    offset += len;
  }

  if (len < 0) {
    perror(progname);
    fprintf(stderr,"%s: unable to read\n",progname);
    exit(1);
  }

  /* parse the response from emacs, getting client fd & result length */
  buf[offset] = '\0';
  sscanf(buf,"%d/%d", &s, &result_len);

  while (result_len > 0) {
    if ((len = read(0,buf,min2(result_len,GSERV_BUFSZ))) < 0) {
      perror(progname);
      fprintf(stderr,"%s: unable to read\n",progname);
      exit(1);
    }
    buf[len] = '\0';
    send_string(s,buf);
    result_len -= len;
  }

  /* eat the newline */
  while ((len = read(0,buf,1)) == 0)
    ;
  if (len < 0)
    {
      perror(progname);
      fprintf(stderr,"%s: unable to read\n",progname);
      exit(1);
    }
  if (buf[0] != '\n')
    {
      fprintf(stderr,"%s: garbage after result\n",progname);
      exit(1);
    }
  /* send the newline */
  buf[1] = '\0';
  send_string(s,buf);
  close(s);

} /* handle_response */
Exemplo n.º 28
0
Arquivo: speed.c Projeto: nphuc/alg
float solve(float a,float b){
    if(a*b<=0){
        return ABS(a-b);
    }
    a=ABS(a);
    b=ABS(b);
    int x=min2(a,b),y=max2(a,b);
    // t*x+x=yt
    return (float)x/(y-x);
}
Exemplo n.º 29
0
  void GeomSearch3d :: ElemMaxExt(Point3d& minp, Point3d& maxp, const MiniElement2d& elem)
  {
    maxp.X()=(*points)[elem.PNum(1)].P()(0);
    maxp.Y()=(*points)[elem.PNum(1)].P()(1);
    maxp.Z()=(*points)[elem.PNum(1)].P()(2);
    minp.X()=(*points)[elem.PNum(1)].P()(0);
    minp.Y()=(*points)[elem.PNum(1)].P()(1);
    minp.Z()=(*points)[elem.PNum(1)].P()(2);
  
    for (int i=2; i <= 3; i++)
      {
	maxp.X()=max2((*points)[elem.PNum(i)].P()(0),maxp.X());
	maxp.Y()=max2((*points)[elem.PNum(i)].P()(1),maxp.Y());
	maxp.Z()=max2((*points)[elem.PNum(i)].P()(2),maxp.Z());
	minp.X()=min2((*points)[elem.PNum(i)].P()(0),minp.X());
	minp.Y()=min2((*points)[elem.PNum(i)].P()(1),minp.Y());
	minp.Z()=min2((*points)[elem.PNum(i)].P()(2),minp.Z());
      }
  }
Exemplo n.º 30
0
int exec(int op, int a, int b) {
  if (op < 0) { /* Swap a&b if op is negative*/
    int t = a;
    a = b;
    b = t;

    op = -op;
  }

  switch (op) {
  case 0:
    return -a;
    break;
  case 1:
    return a + b;
    break;
  case 2:
    return a - b;
    break;
  case 3:
    return a * b;
    break;
  case 4:
    return a / b;
    break;
  case 5:
    return abs(a);
    break;
  case 6:
    return powl(a, b);
    break;
  case 7:
  case 13:
  case 77:
    return a % b;
    break;
  case 8:
    return max2(a, b);
    break;
  case 9:
    return min2(a, b);
    break;
  case 10:
    return sizeOfNum(a, b);
    break;
  case 11:
    return (N0 + 1) * cos(b * PI) / (a - N1);
    break;
  default:
    if (op < 100)
      return (op % abs(a + 1)) + (op % abs(b + 1));
    return -1;
    break;
  }
}