Beispiel #1
0
int main(void)
{
	int a = 3, b = 5;
	unsigned long long c = -1, d = 500;
	int *p;

	std::cout<<"Test 1"<<std::endl;
	std::cout<<"max of "<<a<<" and "<<b<<" is: "<<get_max(a, b)<<std::endl;
	std::cout<<"max of "<<c<<" and "<<d<<" is: "<<get_max(c, d)<<std::endl;
	std::cout<<std::endl;

#ifdef GET_TYPE_ERROR
	std::cout<<"Test 2"<<std::endl;
	std::cout<<"allocated memory value = "<<*get_memory()<<std::endl;
	std::cout<<std::endl;
#endif /* GET_TYPE_ERROR */

	p = get_memory<int>();
	std::cout<<"Test 2 bis (define GET_TYPE_ERROR for first)"<<std::endl;
	std::cout<<"allocated int value = "<<*p<<", at address "<<p<<std::endl;
	std::cout<<std::endl;

	free(p);
	return 0;
}
Beispiel #2
0
int count_neighbouts_ones(int src[], size_t size, int row, int col)
{
    int countOfOnes = 0;
    int startRow = get_max(0, row - 1);
    int endRow = get_min(BOAR_SIZE - 1, row + 1);
    int startCol = get_max(0, col - 1);
    int endCol = get_min(BOAR_SIZE - 1, col + 1);

    int i;
    for (i = startRow; i <= endRow; i++)
    {
        int j;
        for (j = startCol; j <= endCol; j++)
        {
            if (i == row && j == col)
            {
                continue;
            }
            if (nth_position(src[i], j) == 1)
            {
                countOfOnes++;
            }
        }
    }

    return countOfOnes;
}
Beispiel #3
0
CCPoint Hero::getViewPointByPlayer()
{
	CCLayer* parent = (CCLayer*)getParent();							//获取父节点,也就是内个GameLayer图层
	CCSize mapTiledNum = m_map->getMapSize();				//获取当前地图的图块数
	CCSize tiledSize = m_map->getTileSize();
	CCSize mapSize = CCSizeMake(
		mapTiledNum.width * tiledSize.width,
		mapTiledNum.height * tiledSize.height);						//获取地图的尺寸
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint spritePos = getPosition();									//主角的坐标
	//如果主角的坐标小于屏幕的一半,则取屏幕中点坐标,否则取主角的坐标 
	float x = get_max(spritePos.x,visibleSize.width/2);
	float y = get_max(spritePos.y,visibleSize.height/2);
	//如果X、Y的坐标大于右上角的极限值,则取极限值的坐标(极限值是指
	//不让地图超出屏幕造成出现黑边的极限坐标)
	x = get_min(x,mapSize.width - visibleSize.width / 2);
	y = get_min(y,mapSize.height - visibleSize.height / 2);
	
	CCPoint destPos = ccp(x,y);																		//目标点
	CCPoint centerPos = ccp(visibleSize.width/2,visibleSize.height/2);				//屏幕中点
	//计算屏幕中点和所要移动的目的点之间的距离
	CCPoint viewPos = ccpSub(centerPos,destPos);

	return viewPos;
}
Beispiel #4
0
int main(int argc, char **argv)
{
	int i=0;
	setsignals();
#ifdef RCU_SIGNAL
	rcu_init();
#endif
	setup_test(argc, argv);
	printf("nbthreads %lu nbupdaters %lu nbbuckets %lu perbucket-pbnodes %lu nbtest %d nbreaders %d nbcores %d"
#ifdef POPULATE
			" POPULATE"
#endif
			"\n", 
			nbthreads, nbupdaters, nbbuckets, pbnodes, NB_TEST, nbreaders, get_nbcores());

	for(; i < ITERATION; i++)
		test(i);

	double rops = get_avg(&trd_ops[0],ITERATION);
	double wops = get_avg(&twr_ops[0],ITERATION);
	printf("read ops per micsec = %g\n", rops);
	printf("write ops per micsec = %g\n", wops);
	printf("write/read = %g\n", wops/rops);

	printf("nbmallocs = %g\n", get_avg(&run_mallocs[0],ITERATION));
	printf("nbretry = %g\n", get_avg(&run_retry[0],ITERATION));
	printf("nbrelink = %g\n", get_avg(&run_relink[0],ITERATION));
	printf("nbreprev = %g\n", get_avg(&run_reprev[0],ITERATION));
	printf("nbblockeds = %g\n", get_avg(&run_blockeds[0],ITERATION));

	printf("sucess_search = %g on %g\n", get_avg(&run_sea[0],ITERATION), get_avg(&thd_ops[nbupdaters], nbreaders) );
	printf("sucess_insert = %g on %g\n", get_avg(&run_ins[0],ITERATION), get_avg(&thd_ops[0], nbupdaters)/2);
	printf("sucess_delete = %g on %g\n", get_avg(&run_del[0],ITERATION), get_avg(&thd_ops[0], nbupdaters)/2);
	
	printf("\n");

	printf("avg_max_read = %gus\n", get_max(&run_avg_rd[0],ITERATION));
	printf("avg_avg_read = %gus\n", get_avg(&run_avg_rd[0],ITERATION));
	printf("avg_min_read = %gus\n", get_min(&run_avg_rd[0],ITERATION));
	
	printf("\n");

	printf("avg_max_write = %gus\n", get_max(&run_avg_wr[0],ITERATION));
	printf("avg_avg_write = %gus\n", get_avg(&run_avg_wr[0],ITERATION));
	printf("avg_min_write = %gus\n", get_min(&run_avg_wr[0],ITERATION));

	printf("\n");

	printf("max_read = %gus\n", get_max(&run_max_rd[0],ITERATION));
	printf("min_read = %gus\n", get_min(&run_min_rd[0],ITERATION));
	
	printf("\n");

	printf("max_write = %gus\n", get_max(&run_max_wr[0],ITERATION));
	printf("min_write = %gus\n", get_min(&run_min_wr[0],ITERATION));

	//printf("cpu time = %gus\n", get_avg(&run_cput[0],ITERATION));//FIXME

	return 0;
}
Beispiel #5
0
/* get the max valuable position */
int get_max_think(int *x, int *y)
{
	int cx;
	int cy;
	int px;
	int py;
	int maxc = 0, maxp = 0;
	get_max(&px, &py, perboard, &maxp, 1);
	get_max(&cx, &cy, comboard, &maxc, 2);
	if (maxc == 0) {
		*x = px;
		*y = py;
	} else {
		if ((maxp == 3 && maxc == 3) && !keyc && keyp) {
			*x = px;
			*y = py;
			keyp = 0;
		}
		keyc = 0;
		keyp = 0;
		if (maxp >= 2 && maxc < maxp) {
			*x = px;
			*y = py;
		} else {
			*x = cx;
			*y = cy;
		}
	}

	return 0;
}
double get_y (int n, double x, double y, double step) {
    double cur = get_max(n,x,y);
    while(cur > get_max(n,x,y+step)) {
        cur = get_max(n,x,y+step);
        y = y + step;
    }
    return y;
}
// get x with optimal d
double get_x (int n, double x, double y, double step) {
    double cur = get_max(n,x,y);
    while(cur > get_max(n,x+step,y)) {
        cur = get_max(n,x+step,y);
        x = x + step;
    }
    return x;
}
Beispiel #8
0
int main(int argc, const char *argv[])
{
    int a[10] = {1,2,23,6,8,10,0};
    char b[8] = {23,5,7,78,2,3,77};

    printf("%d\n",*((int *)get_max(a, 10, 4, cmp_int)));
    printf("%d\n",*((char *)get_max(b, 8, 1, cmp_char)));

    return 0;
}
Beispiel #9
0
int main(int argc, const char *argv[])
{
    int a[]={1,2,5,6,10,7,3,8,4};
    char b[]={'a','f','e','d','b','c'};
    int *ret1,*ret2;
    ret1 = get_max(a,9,4,cmp_int);
    ret2 = get_max(b,6,1,cmp_char);
    printf("%d,%p\n",*ret1,ret1);
    printf("%c,%p\n",*ret2,ret2);
    return 0;
}
Beispiel #10
0
int main(int argc, const char *argv[])
{
    int a[10]={1,2,3,5,4,6,9,8,7};
    char b[10]={1,4,5,2,0,1,8,7,6};
    int * ret;
    ret =(int *)get_max(a , 10 , 4 , cmp_int);
    printf("cmp_int max =%d\n",*ret);
    ret =(int *)get_max(b , 10 , 1 , cmp_char);
    printf("cmp_char max =%d\n",*(char *)ret);
    return 0;
}
Beispiel #11
0
void Range::set_unit_value(double p_value) {
	if (shared->exp_unit_value && get_min()>0) {

		double exp_min = Math::log(get_min())/Math::log(2);
		double exp_max = Math::log(get_max())/Math::log(2);
		double v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value);

		set_val( v );
	} else {
		set_val( (get_max() - get_min()) * p_value + get_min() );
	}
}
Beispiel #12
0
double Range::get_as_ratio() const {

	if (shared->exp_ratio && get_min() > 0) {

		double exp_min = Math::log(get_min()) / Math::log((double)2);
		double exp_max = Math::log(get_max()) / Math::log((double)2);
		double v = Math::log(get_value()) / Math::log((double)2);

		return (v - exp_min) / (exp_max - exp_min);

	} else {

		return (get_value() - get_min()) / (get_max() - get_min());
	}
}
Beispiel #13
0
double Range::get_unit_value() const {

	if (shared->exp_unit_value && get_min()>0) {

		double exp_min = Math::log(get_min())/Math::log(2);
		double exp_max = Math::log(get_max())/Math::log(2);
		double v = Math::log(get_val())/Math::log(2);

		return (v - exp_min) / (exp_max - exp_min);

	} else {

		return (get_val() - get_min()) / (get_max() - get_min());
	}
}
int thread_fn(void *data)
{
  short cpu_temp,gpu_temp,max_temp;
  set_current_state(TASK_INTERRUPTIBLE);
  while(!kthread_should_stop())
  {
    SLEEP_MILLI_SEC(30000);
    cpu_temp = 0;
    gpu_temp = 0;
    cpu_temp = read_ec(0xA8);
    gpu_temp = read_ec(0xAF);
    max_temp = get_max(cpu_temp, gpu_temp);
    if (max_temp < 60) {
      fanSpeed = minFanSpeed;
    }

    if (max_temp > 60) {
      fanSpeed = minFanSpeed+20;
    }

    if (max_temp > 70) {
      fanSpeed = minFanSpeed+40;
    }

    if (max_temp > 80) {
      fanSpeed = maxFanSpeed;
    }
    set_speed(fanSpeed);
    printk(KERN_INFO "cpu temp: %d, gpu temp: %d, fan speed: %d", cpu_temp, gpu_temp, fanSpeed);
    schedule();
    set_current_state(TASK_INTERRUPTIBLE);
  }
  set_current_state(TASK_RUNNING);
  return 0;
}
Beispiel #15
0
void sort(int array[], int l)
{
    int max = get_max(array, l);
    int multp_of_ten;
    for (multp_of_ten = 1; max / multp_of_ten > 0; multp_of_ten *= 10)
        count(array, l, multp_of_ten);
}
float ControlPort::get_normalized() const {

	float v=get();
	v-=get_min();
	v/=get_max()-get_min();
	return v;
}
Beispiel #17
0
int main()
{

	int array[]={1,2,3,-2,-7,9,2,-1};

	get_max(array,sizeof(array)/sizeof(int));
}
Beispiel #18
0
 blockstep_iterator& operator++() {
     if (inc_subblock<5>()) return *this;
     reset_subblock<5>();
     if (inc_subblock<4>()) return *this;
     reset_subblock<4>();
     if (inc_subblock<3>()) return *this;
     reset_subblock<3>();
     if (inc_subblock<2>()) return *this;
     reset_subblock<2>();
     if (inc_subblock<1>()) return *this;
     reset_subblock<1>();
     if (inc_subblock<0>()) return *this;
     reset_subblock<0>();
     
     if (inc_block<5>()) return *this;
     reset_block<5>();
     if (inc_block<4>()) return *this;
     reset_block<4>();
     if (inc_block<3>()) return *this;
     reset_block<3>();
     if (inc_block<2>()) return *this;
     reset_block<2>();
     if (inc_block<1>()) return *this;
     reset_block<1>();
     if (inc_block<0>()) return *this;
     cur = get_max();
     return  *this;
 }
Beispiel #19
0
t_data			*full_data(struct dirent *info, t_data *parent)
{
	t_data		*data;
	char		*path;

	path = ft_strjoin("/", info->d_name);
	data = NULL;
	if (!(data = (t_data *)malloc(sizeof(t_data))))
		return (NULL);
	data->path = build_path(parent->path, path);
	if (!fill_stat_in_data(data))
		return (NULL);
	data->name = ft_strdup(info->d_name);
	data->type = info->d_type;
	data->tree = NULL;
	data->r_tree = NULL;
	data->cmp = parent->cmp;
	if (data->perms[0] == 'l')
		data->lnk = ft_get_lnk(data->path);
	else
		data->lnk = NULL;
	data->print = parent->print;
	data->max = parent->max;
	get_max(data);
	return (data);
}
Beispiel #20
0
void scan_look()
{
	int i,min,max;
	max = get_max();
	min = get_min();
	if(head == 0){
		turn = 1;
		head = min;
	}
	if(turn == 0)
	for(i=head;i>=0;i--){
		if(mark[i] == 1)
			continue;
		if(sector[i] == 1){
			mark[i] = 1;
			head = i;
			break;
		}
	}
	else
		for(i=head;i<=max;i++){
			if(mark[i] == 1)
				continue;
			if(sector[i] == 1){
				mark[i] = 1;
				head = i;
				break;
			}
		}
	if(head == min)
		turn = 1;
}
Beispiel #21
0
void c_scan_c_look()
{
	int i,min,max;
	max = get_max();
	min = get_min();
	if(head == MAX_SEC -1){
		turn = 1;
		head = max;
	}
	if(turn == 0)
	for(i=head;i<MAX_SEC;i++){
		if(mark[i] == 1)
			continue;
		if(sector[i] == 1){
			mark[i] = 1;
			head = i;
			break;
		}
	}
	else
		for(i=0;i<head_bak;i++){
			if(mark[i] == 1)
				continue;
			if(sector[i] == 1){
				mark[i] = 1;
				head = i;
				break;
			}
		}
	if(head == max)
		turn = 1;
}
void ControlPort::set_normalized(float p_val,bool p_make_initial) {

	p_val*=get_max()-get_min();
	p_val+=get_min();
	set(p_val,p_make_initial);

}
Beispiel #23
0
void heapify(int vector[], int dad){
  int larger = get_max(vector,dad);

  if(larger != dad){
    swap(vector[dad], vector[larger]);
    heapify(vector,larger);
  }
}
Beispiel #24
0
void
selectionsort(int A[], int n) {
	int i, max_pos;
	for(i = n; i >= 0; i--) {
		max_pos = get_max(A, i);
		swap(&A[i],&A[max_pos]);
	}
}
Beispiel #25
0
double Range::get_as_ratio() const {

	if (shared->exp_ratio && get_min() >= 0) {

		double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);
		double exp_max = Math::log(get_max()) / Math::log((double)2);
		float value = CLAMP(get_value(), shared->min, shared->max);
		double v = Math::log(value) / Math::log((double)2);

		return (v - exp_min) / (exp_max - exp_min);

	} else {

		float value = CLAMP(get_value(), shared->min, shared->max);
		return (value - get_min()) / (get_max() - get_min());
	}
}
Beispiel #26
0
int main(int argc, char *argv[])
{
    char a[10] ={"slkdwldk"};

    get_max(a, strlen(a), cmp);

    return 0;
}
Beispiel #27
0
void get_max_local(){
   node_ptr search;
   search = (node_ptr)get_max();
   if(search==(node_ptr)NULL)
      printf("empty tree.\n");
   else
      printf("maximum value: %l\n",search->key);
}
int get_max(struct TreeNode *root,int *max){
    if(root == NULL)
        return 0;

    int left = get_max(root->left,max);
    int right = get_max(root->right,max);
    int ret;
    int tmp;
        
    ret = root->val > root->val + left ? root->val : root->val + left;
    ret = ret > root->val + right ? ret : root->val + right;
    
    tmp = root->val + left + right;
    *max = tmp > *max ? tmp : *max;
    
    return ret < 0 ? 0 : ret;
}
Beispiel #29
0
// Initializes channels.
//
// Parameters:
//   n_channels     the number of channels
//   in_format      the input format code
//   out_format     the output format code
//   sampling_rate  the sampling rate
//   apply_dither   true to apply dither to output
//
// Returns:
//    0 if successful
//   -1 if channel limit is exceeded
int
brutefir::init_channels(int n_channels,
                        int in_format,
                        int out_format,
                        int sampling_rate,
                        bool apply_dither)
{
    int n;

    if (n_channels > BF_MAXCHANNELS)
    {
        pinfo("Number of channels (%u) exceeds limit (%u).", n_channels, BF_MAXCHANNELS);
        return -1;
    }

    bfconf->sampling_rate = sampling_rate;
    bfconf->n_channels = n_channels;

    // setup inputs and outputs
    for (n = 0; n < bfconf->n_channels; n++)
    {
        setup_input(n, in_format);
        setup_output(n, out_format, apply_dither);
    }

    // initialize overflow structure
    memset(overflow, 0, sizeof(struct bfoverflow_t) * bfconf->n_channels);
    memset(last_overflow, 0, sizeof(struct bfoverflow_t) * bfconf->n_channels);

    for (n = 0; n < bfconf->n_channels; n++)
    {
        if (bfconf->outputs[n].bf.sf.isfloat)
        {
            overflow[n].max = 1.0;
            last_overflow[n].max = 1.0;
        }
        else
        {
            overflow[n].max = get_max(bfconf->outputs[n].bf.sf.bytes);
            last_overflow[n].max = get_max(bfconf->outputs[n].bf.sf.bytes);
        }
    }

    return 0;
}
Beispiel #30
0
void draw_hyperbolic_arc(double x0, double y0, double a, double b,
			 double f, double g, double c, double s)
{
    double e;

    e = Atan(b/get_max(x0, y0));
    if (f < -e) draw_branch(-180 + e, -e, x0, y0, a, b, f, g, c, s);
    if (g > e) draw_branch(e, 180 - e, x0, y0, a, b, f, g, c, s);
}