Exemple #1
0
int main()
{
	int data1 = 10;
	int data2 = 20;
	int result;
	GREATER(data1, data2, result);
	printf("a = %d, b = %d result: %d\n", data1, data2, result);
	data1 = 30;
	GREATER(data1, data2, result);
	printf("a = %d, b = %d result: %d\n", data1, data2, result);
	return 0;
}
inline static void siftdown( table_t *t, unsigned int heapsize, uint4 parent )
{
	entry_t *heap = t->heap;
	unsigned int child = parent*2 + 1;
	entry_t tmp;

	while ( child < heapsize ) {
		if ( child+1 < heapsize && GREATER(heap[child], heap[child+1]) ) {
			child++;
		}
		if ( GREATER(heap[parent], heap[child] ) ) {
			memcpy( &tmp, &heap[parent], sizeof(entry_t) );
			memcpy( &heap[parent], &heap[child], sizeof(entry_t) );
			memcpy( &heap[child], &tmp, sizeof(entry_t) );
		}
		else {
			return;
		}
		parent = child;
		child = (parent*2)+1;
	}
}
Exemple #3
0
static void draw_bpm(Layer *this_layer, GContext *ctx, int y, int current_bpm) {
  GRect bounds = layer_get_bounds(this_layer);

  int16_t step_per_pixel = (25*bounds.size.w)/100;
  
  int16_t offset = 0-current_bpm*step_per_pixel/10;
  
  int bpm = current_bpm-(current_bpm % 5);
  for(bpm = GREATER(bpm-25, 0); bpm <= current_bpm+25; bpm += 5) {
      if (bpm%15) {
  	    int16_t x = bpm*step_per_pixel/10+offset+bounds.size.w/2;
  	    if (x > 0 && x < bounds.size.w)
    	  	graphics_draw_line(ctx, GPoint(x, y), GPoint(x, y+3));
      }
  }

  bpm = current_bpm-(current_bpm % 15);
  for(bpm = GREATER(bpm-30, 0); bpm <= current_bpm+30; bpm += 15) {
  	  int16_t x = bpm*step_per_pixel/10+offset;
  	  
  	  GRect frame = GRect(x, y-8, bounds.size.w, 14);
  	  
  	  static char s_buffer[12];
  	  snprintf(s_buffer, 10, "%d", bpm);
  	  
  	  graphics_draw_text(ctx, 
  	  	s_buffer,
    	fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD),
    	frame,
    	GTextOverflowModeTrailingEllipsis,
    	GTextAlignmentCenter,
    	NULL
  	  );  	  
  	    
  }
}
Exemple #4
0
static void draw_step(Layer *this_layer, GContext *ctx, int y, int total_steps) {
  GRect bounds = layer_get_bounds(this_layer);

  int16_t step_per_pixel = (bounds.size.w)/100;
  
  int16_t offset = 0-total_steps*step_per_pixel/10;
  
  int step = total_steps-(total_steps % 100);
  for(step = GREATER(step-1000, 0); step <= total_steps+1000; step += 100) {
      if (step%500) {
  	    int16_t x = step*step_per_pixel/10+offset+bounds.size.w/2;
  	    if (x > 0 && x < bounds.size.w)
    	  	graphics_draw_line(ctx, GPoint(x, y), GPoint(x, y+3));
      }
  }

  step = total_steps-(total_steps % 500);
  for(step = GREATER(step-1000, 0); step <= total_steps+1000; step += 500) {
  	  int16_t x = step*step_per_pixel/10+offset;
  	  
  	  GRect frame = GRect(x, y-8, bounds.size.w, 14);
  	  
  	  static char s_buffer[8];
  	  snprintf(s_buffer, 8, "%d", step);
  	  
  	  graphics_draw_text(ctx, 
  	  	s_buffer,
    	fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD),
    	frame,
    	GTextOverflowModeTrailingEllipsis,
    	GTextAlignmentCenter,
    	NULL
  	  );  	  
  	    
  }
}
Exemple #5
0
static BaumKnoten Finde(Baum *Wurzel, BaumKnoten Zweig, BaumKeyType Key)
{
   if (Zweig == NULL)
   {
      return(NULL);
   }
   else if (SMALLER(Wurzel->Compare(Key, Zweig->Key)))
   {
      return(Finde(Wurzel, Zweig->Left, Key));
   }
   else if (GREATER(Wurzel->Compare(Key, Zweig->Key)))
   {
      return(Finde(Wurzel, Zweig->Right, Key));
   }
   else
   {
      return(Zweig);
   }
}
inline static void siftup( table_t *t, unsigned int child )
{
	entry_t *heap = t->heap;
	unsigned int parent = (child-1) >> 1;
	entry_t tmp;

	while ( child > 0 ) {
		if ( GREATER(heap[parent],heap[child]) ) {
			memcpy( &tmp, &heap[parent], sizeof(entry_t) );
			memcpy( &heap[parent], &heap[child], sizeof(entry_t) );
			memcpy( &heap[child], &tmp, sizeof(entry_t) );
		}
		else {
			return;
		}

		child = parent;
		parent = (child-1) >> 1;
	}
}
bool isOut(const SrPoint3D& point,const SrSphere3D& sphere)
{
	if( GREATER((sphere.mCenter - point).magnitudeSquared(), sphere.mRadius*sphere.mRadius) )
		return true;
	return false;
}
Exemple #8
0
PLUS()MINUS()                 //R +- 
STRINGIZE( PLUS()MINUS() )    //R "+-" 
//R 
PLUS()PLUS()                  //R + + 
STRINGIZE( PLUS()PLUS() )     //R "++" 
//R 
MINUS()MINUS()                //R - - 
STRINGIZE( MINUS()MINUS() )   //R "--" 
//R 
DOT()DOT()DOT()               //R .. . 
STRINGIZE( DOT()DOT()DOT() )  //R "..." 

// the following are regressions reported by Stefan Seefeld
//R #line 43 "t_9_003.cpp"
GREATER()GREATER()            //R > > 
STRINGIZE( GREATER()GREATER() ) //R ">>" 
//R
LESS()LESS()                  //R < < 
STRINGIZE( LESS()LESS() )     //R "<<" 

#define COMMA() ,
#define AND() &
#define CHAR() char
#define STAR() *

// Make sure no whitespace gets inserted in between the operator symbols
//R #line 56 "t_9_003.cpp"
void foo(char&, char)               //R void foo(char&, char) 
void foo(char *)                    //R void foo(char *) 
void foo(char *&)                   //R void foo(char *&) 
void foo(CHAR()AND()COMMA() CHAR()) //R void foo(char&, char) 
input_t get_input(int nlhs,int nrhs,const mxArray *prhs[]) {
  input_t input;
  int n,i;
  double *x,*ry_temp,*iy_temp,*third,fourth,fifth;
  COMPLEX_T *y;
  
  input.stop_params.threshold = DEFAULT_THRESHOLD;
  input.stop_params.tolerance = DEFAULT_TOLERANCE;
  input.allocated_x=0;
  #ifdef _ALT_MEXERRMSGTXT_
  input.error_flag=0;
  #endif
  input.max_imfs=0;
  input.nbphases=DEFAULT_NBPHASES;
  
  /* argument checking*/
  if (nrhs>5)
    mexErrMsgTxt("Too many arguments");
  if (nrhs<2)
    mexErrMsgTxt("Not enough arguments");
  if (nlhs>2)
    mexErrMsgTxt("Too many output arguments");
  if (!mxIsEmpty(prhs[0]))
    if (!mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0]) ||
    mxIsSparse(prhs[0]) || !mxIsDouble(prhs[0]) ||
    (mxGetNumberOfDimensions(prhs[0]) > 2))
      mexErrMsgTxt("X must be either empty or a double precision real vector.");
  
  if (!mxIsNumeric(prhs[1]) || !mxIsComplex(prhs[1]) ||
  mxIsSparse(prhs[1]) || !mxIsDouble(prhs[1]) ||/* length of vector x */
  (mxGetNumberOfDimensions(prhs[1]) > 2))
    mexErrMsgTxt("Y must be a double precision complex vector.");
  
  /* input reading: x and y */
  n=GREATER(mxGetN(prhs[1]),mxGetM(prhs[1])); /* length of vector x */
  if (mxIsEmpty(prhs[0])) {
    input.allocated_x = 1;
    x = (double *)malloc(n*sizeof(double));
    for(i=0;i<n;i++) x[i] = i;
  }
  else
    x=mxGetPr(prhs[0]);
  ry_temp=mxGetPr(prhs[1]);
  iy_temp=mxGetPi(prhs[1]);
  
  /* third argument */
  if (nrhs>=3) {
    if(!mxIsEmpty(prhs[2])) {
      if (!mxIsNumeric(prhs[2]) || mxIsComplex(prhs[2]) || mxIsSparse(prhs[2])
      || !mxIsDouble(prhs[2]) || (mxGetN(prhs[2])!=1 && mxGetM(prhs[2])!=1))
        mexPrintf("STOP must be a real vector of 1 or 2 elements");
      i = GREATER(mxGetN(prhs[2]),mxGetM(prhs[2]));
      if (i>2)
        mexErrMsgTxt("STOP must be a vector of 1 or 2 elements");
      third=mxGetPr(prhs[2]);
      switch (i) {
        case 1 : {
          input.stop_params.threshold=*third;
          break;
        }
        case 2 : {
          input.stop_params.threshold=third[0];
          input.stop_params.tolerance=third[1];
        }
      }
      /* input checking */
      if (input.stop_params.threshold <= 0)
        mexErrMsgTxt("threshold must be a positive number");
      if (input.stop_params.threshold >= 1)
        mexWarnMsgTxt("threshold should be lower than 1");
      if (input.stop_params.tolerance < 0 || input.stop_params.tolerance >= 1)
        mexErrMsgTxt("tolerance must be a real number in [O,1]");
    }
  }
  
  
  /* fourth argument */
  if (nrhs>=4) {
    if (!mxIsEmpty(prhs[3])) { /* if empty -> do nothing */
      if (!mxIsNumeric(prhs[3]) || mxIsComplex(prhs[3]) || mxIsSparse(prhs[3])
      || !mxIsDouble(prhs[3]) || mxGetN(prhs[3])!=1 || mxGetM(prhs[3])!=1)
        mexErrMsgTxt("NB_IMFS must be a positive integer");
      fourth=*mxGetPr(prhs[3]);
      if ((unsigned int)fourth != fourth)
        mexErrMsgTxt("NB_IMFS must be a positive integer");
      input.max_imfs=(int)fourth;
    }
  }
  
  /* fifth argument */
  if (nrhs==5) {
    if(!mxIsNumeric(prhs[4]) || mxIsComplex(prhs[4]) || mxIsSparse(prhs[4])
    || mxGetN(prhs[4])!=1 || mxGetM(prhs[4])!=1)
      mexErrMsgTxt("NBPHASES must be a positive integer");
    fifth=*mxGetPr(prhs[4]);
    if ((int)fifth != fifth)
      mexErrMsgTxt("NBPHASES must be a positive integer");
    input.nbphases = (int)fifth;
  }
  
  
  /* more input checking */
  if (!input.allocated_x && SMALLER(mxGetN(prhs[0]),mxGetM(prhs[0]))!=1 ||
  SMALLER(mxGetN(prhs[1]),mxGetM(prhs[1]))!=1)
    mexErrMsgTxt("X and Y must be vectors");
  if (GREATER(mxGetN(prhs[1]),mxGetM(prhs[1]))!=n)
    mexErrMsgTxt("X and Y must have the same length");
  i=1;
  while (i<n && x[i]>x[i-1]) i++;
  if (i<n) mexErrMsgTxt("Values in X must be non decreasing");
  
  /* copy vector y to avoid erasing input data */
  y=(COMPLEX_T *)malloc(n*sizeof(COMPLEX_T));
  #ifdef C99_OK
  for (i=0;i<n;i++) y[i]=ry_temp[i]+I*iy_temp[i];
  #else
  for (i=0;i<n;i++) {
    y[i].r=ry_temp[i];
    y[i].i=iy_temp[i];
  }
  #endif
  
  input.n=n;
  input.x=x;
  input.y=y;
  return input;
}
SrReal SrRay3D::distanceSegmentSquared(const SrSegment3D& segment)const
{
	SrVector3D direction = segment.mPoint2 - segment.mPoint1;
	SrVector3D u = mBase - segment.mPoint1;
	SrReal a = mDirection.dot(mDirection);
	SrReal b = mDirection.dot(direction);
	SrReal c = direction.dot(direction);
	SrReal d = mDirection.dot(u);
	SrReal e = direction.dot(u);
	SrReal det = a*c - b*b;
	SrReal sNum,sDenom,tNum,tDenom;
	tDenom = sDenom = det;
	if( EQUAL(det,0) )
	{
		sNum = 0;
		tNum = e;
		tDenom = c;
	}
	else
	{
		sNum = b*e - c*d;
		tNum = a*e - b*d;
	}
	//check s
	if( LESS(sNum,0) )
	{
		sNum = 0;
		tNum = e;
		tDenom = c;
	}

	//check t
	if( LESS(tNum,0) )
	{
		tNum = 0;
		if( LESS(-d,0) )
		{
			sNum = 0;
		}
		else
		{
			sNum = -d;
			sDenom  = a;
		}
	}
	else if( GREATER(tNum,tDenom) )
	{
		tNum = tDenom;
		if( LESS((-d + b),0) )
			sNum = 0;
		else
		{
			sNum = -d + b;
			sDenom = a;
		}
	}
	// Parameters of nearest points on restricted domain
	SrReal s = 0  , t = 0;
	if( UNEQUAL(sDenom,0) )
		s= sNum / sDenom ;
	if( UNEQUAL(tDenom,0) )
		t = tNum / tDenom;

	SrVector3D v = u + s*mDirection - t*direction;
	return v.dot(v);
}