当前位置: 首页>>代码示例>>C++>>正文


C++ POW2函数代码示例

本文整理汇总了C++中POW2函数的典型用法代码示例。如果您正苦于以下问题:C++ POW2函数的具体用法?C++ POW2怎么用?C++ POW2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了POW2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: gif2bmp

int gif2bmp(tGIF2BMP *gif2bmp, FILE *inputFile, FILE *outputFile)
{
	u_int16_t biBitCount;
	tGIF *img;

	// load image into memory
	if ((img = gif_load(inputFile)) == NULL)
		return -1;

	// decompress the image's data
	if (gif_lzw_decompression(img) != 0)
		return -1;

	struct logical_screen_descriptor *lsd = &(img->screen_desc);
	struct image_descriptor *id = &(img->image_desc);
	int color_tab_size = (lsd->glob_colors) ? lsd->glob_colors_len : id->local_colors_len;
	u_int32_t bfOffBits = FILEHEADER_SIZE+INFOHEADER_SIZE+4*(POW2(color_tab_size+1));

	bmp_add_fileHeader(outputFile, bfOffBits);
	biBitCount = bmp_add_infoHeader(outputFile, img, color_tab_size);
	bmp_add_rgbQuad(outputFile, img->colors_tab, POW2(color_tab_size+1));
	bmp_add_bits(outputFile, img, biBitCount);

	gif2bmp->bmpSize = bmp_add_bfSize(outputFile);
	gif2bmp->gifSize = img->size;

	gif_unload(img);

	return 0;
}
开发者ID:mmsrubar,项目名称:gif2bmp,代码行数:30,代码来源:gif2bmp.c

示例2: mousePressEvent

void RangeLevelEditor::mousePressEvent(QMouseEvent *e) {

	if (!scale_1 || !scale_2 || !range_1 || !range_2)
		return;

	if (e->button()!=Qt::LeftButton)
		return;

	float press_x=(float)e->x()/(float)width();
	float press_y=(float)(height()-e->y())/(float)height();
	
	float dist_1=sqrt(POW2(press_x-range_1->get())+POW2(press_y-scale_1->get()));
	float dist_2=sqrt(POW2(press_x-range_2->get())+POW2(press_y-scale_2->get()));
	
	int closer=(dist_1<dist_2)?1:2; //which is closer?
	float closer_dist=(closer==1)?dist_1:dist_2; //distance of closer
	
	
	click.drag_point=closer;
	click.scale=(closer==1)?scale_1->get():scale_2->get();
	click.range=(closer==1)?range_1->get():range_2->get();
	click.point=e->pos();
	
	

}
开发者ID:BackupTheBerlios,项目名称:reshaked-svn,代码行数:26,代码来源:range_level_editor.cpp

示例3: cylinder_centers_distance

double
cylinder_centers_distance (CYLINDER *c1, CYLINDER *c2)
{
	return sqrt (POW2 (c1->x - c2->x) +
		     POW2 (c1->y - c2->y) +
		     POW2 (c1->z - c2->z));
}
开发者ID:LCAD-UFES,项目名称:MAE,代码行数:7,代码来源:cylinder.c

示例4: colordiff

static inline gfloat colordiff (gfloat *pixA,
                                gfloat *pixB)
{
    return POW2(pixA[0]-pixB[0])+
           POW2(pixA[1]-pixB[1])+
           POW2(pixA[2]-pixB[2]);
}
开发者ID:jcupitt,项目名称:gegl-vips,代码行数:7,代码来源:snn-percentile.c

示例5: cosmoPk_forceSigma8

extern double
cosmoPk_forceSigma8(cosmoPk_t pk,
                    double    sigma8,
                    double    kmin,
                    double    kmax,
                    double    *error)
{
	double sigma8Actual;
	double sigma8First;
	int    numIter    = 0;
	int    numIterMax = LOCAL_MAX_FORCESIGMA8_ITERATIONS;

	assert(pk != NULL);
	assert(isgreater(sigma8, 0.0));
	assert(isgreater(kmin, 0.0));
	assert(isgreater(kmax, kmin));
	assert(error != NULL);

	sigma8Actual = cosmoPk_calcSigma8(pk, kmin, kmax, error);
	sigma8First  = sigma8Actual;
	do {
		cosmoPk_scale(pk, POW2(sigma8 / sigma8Actual));
		sigma8Actual = cosmoPk_calcSigma8(pk, kmin, kmax, error);
		*error       = fabs(1. - sigma8 / sigma8Actual);
		numIter++;
	} while (numIter < numIterMax && isgreater(*error, 1e-10));
	if (numIter >= numIterMax)
		fprintf(stderr, "Exhausted iterations in %s: error %15.13e\n",
		        __func__, *error);

	return POW2(sigma8 / sigma8First);
}
开发者ID:satlank,项目名称:ginnungagap,代码行数:32,代码来源:cosmoPk.c

示例6: L2Distance

/*If square == 1, the square of the L2 is returned*/
real L2Distance(SparseDim* x, SparseDim* z,uchar square) {
    real res = 0.0;
    SparseElem* x_elem = x->first;
    SparseElem* z_elem = z->first;

    while(x_elem || z_elem) {
        if(x_elem && z_elem) {
            if(x_elem->c < z_elem->c) {
                res += POW2(x_elem->val);
                x_elem = x_elem->nextC;
            }
            else if (x_elem->c > z_elem->c) {
                res += POW2(z_elem->val);
                z_elem = z_elem->nextC;
            }
            else {
                res += POW2((x_elem->val) - (z_elem->val));
                x_elem = x_elem->nextC;
                z_elem = z_elem->nextC;
            }
        }
        else {
            if(x_elem) {
                res += POW2(x_elem->val);
                x_elem = x_elem->nextC;
            }
            else {
                res += POW2(z_elem->val);
                z_elem = z_elem->nextC;
            }
        }
    }

    /*if(res == 0.0){
    	fprintf(stderr,"Null distance\n");
    	if(x_elem == z_elem)
    		fprintf(stderr,"Pointers are the same\n");
    	fprintf(stderr,"Vector x : \n");
    	x_elem = x->first;
    	while(x_elem){
    		fprintf(stderr," %i:%e",(x_elem->c)+1,x_elem->val);
    		x_elem = x_elem->nextC;
    	}
    	fprintf(stderr,"\n");
    	fprintf(stderr,"Vector z : \n");
    	z_elem = z->first;
    	while(z_elem){
    		fprintf(stderr," %i:%e",(z_elem->c)+1,z_elem->val);
    		z_elem = z_elem->nextC;
    	}
    	fprintf(stderr,"\n");
    	fflush(stderr);
    	exit(EXIT_FAILURE);
    }*/

    if (square)
        return res;
    else
        return (real)sqrt(res);
}
开发者ID:kfrancoi,项目名称:dwalk,代码行数:61,代码来源:similarity.c

示例7: vp_os_mutex_lock

control_t *route_control_create(route_t* route) {
		if (route == NULL)
				return NULL;

		control_t *control = (control_t*)vp_os_malloc(sizeof(control_t));
		control_t *control_head = control;
		NODE_T *target = route->head;

		if (target == NULL)
				return NULL;

		//INIT_CONTROL(control, 0, 0, 0);

		angle_t hori_angle;
		angle_t vert_angle;
		distance_t distance;

		vp_os_mutex_lock(&NOW_mutex);
		distance_t last_x = NOW.x;
		distance_t last_y = NOW.y;
		distance_t last_z = NOW.z;
		vp_os_mutex_unlock(&NOW_mutex);

		while (target != NULL) {
				//get paras
				distance_t vect_x = target->x - last_x;
				distance_t vect_y = target->y - last_y;
				distance_t vect_z = target->z - last_z;

				printf("last %lf %lf %lf\n", last_x, last_y, last_z);
				printf("vect %lf %lf %lf\n", vect_x, vect_y, vect_z);

				last_x = target->x;
				last_y = target->y;
				last_z = target->z;

				//calcu
				MAKE_HORI_ANGLE(hori_angle, vect_x, vect_y);
				MAKE_VERT_ANGLE(vert_angle, vect_x, vect_y, vect_z);
				distance = sqrt(POW2(vect_x) + POW2(vect_y) + POW2(vect_z)) * route->unit_distance;
				
				//init control node
				INIT_CONTROL(control, hori_angle, vert_angle, distance);

				printf("control dis%lf angle%lf\n", control->distance, control->hori_angle);
				
				if (target->next != NULL) {
						control->next = (control_t*)vp_os_malloc(sizeof(control_t));
						control = control->next;
				}


				target = target->next;
		}

		return control_head;
}
开发者ID:EricWen229,项目名称:autodrone-fightnview,代码行数:57,代码来源:auto_control_demo.c

示例8: spheroid_project

/**
* Given a location, an azimuth and a distance, computes the
* location of the projected point. Based on Vincenty's formula
* for the geodetic direct problem as described in "Geocentric
* Datum of Australia Technical Manual", Chapter 4. Tested against:
* http://mascot.gdbc.gov.bc.ca/mascot/util1b.html
* and
* http://www.ga.gov.au/nmd/geodesy/datums/vincenty_direct.jsp
*
* @param r - location of first point.
* @param distance - distance in meters.
* @param azimuth - azimuth in radians.
* @return s - location of projected point.
*/
int spheroid_project(const GEOGRAPHIC_POINT *r, const SPHEROID *spheroid, double distance, double azimuth, GEOGRAPHIC_POINT *g)
{
	double omf = 1 - spheroid->f;
	double tan_u1 = omf * tan(r->lat);
	double u1 = atan(tan_u1);
	double sigma, last_sigma, delta_sigma, two_sigma_m;
	double sigma1, sin_alpha, alpha, cos_alphasq;
	double u2, A, B;
	double lat2, lambda, lambda2, C, omega;
	int i = 0;

	if (azimuth < 0.0)
	{
		azimuth = azimuth + M_PI * 2.0;
	}
	if (azimuth > (PI * 2.0))
	{
		azimuth = azimuth - M_PI * 2.0;
	}

	sigma1 = atan2(tan_u1, cos(azimuth));
	sin_alpha = cos(u1) * sin(azimuth);
	alpha = asin(sin_alpha);
	cos_alphasq = 1.0 - POW2(sin_alpha);

	u2 = spheroid_mu2(alpha, spheroid);
	A = spheroid_big_a(u2);
	B = spheroid_big_b(u2);

	sigma = (distance / (spheroid->b * A));
	do
	{
		two_sigma_m = 2.0 * sigma1 + sigma;
		delta_sigma = B * sin(sigma) * (cos(two_sigma_m) + (B / 4.0) * (cos(sigma) * (-1.0 + 2.0 * POW2(cos(two_sigma_m)) - (B / 6.0) * cos(two_sigma_m) * (-3.0 + 4.0 * POW2(sin(sigma))) * (-3.0 + 4.0 * POW2(cos(two_sigma_m))))));
		last_sigma = sigma;
		sigma = (distance / (spheroid->b * A)) + delta_sigma;
		i++;
	}
	while (i < 999 && fabs((last_sigma - sigma) / sigma) > 1.0e-9);

	lat2 = atan2((sin(u1) * cos(sigma) + cos(u1) * sin(sigma) *
	              cos(azimuth)), (omf * sqrt(POW2(sin_alpha) +
	                                         POW2(sin(u1) * sin(sigma) - cos(u1) * cos(sigma) *
	                                              cos(azimuth)))));
	lambda = atan2((sin(sigma) * sin(azimuth)), (cos(u1) * cos(sigma) -
	               sin(u1) * sin(sigma) * cos(azimuth)));
	C = (spheroid->f / 16.0) * cos_alphasq * (4.0 + spheroid->f * (4.0 - 3.0 * cos_alphasq));
	omega = lambda - (1.0 - C) * spheroid->f * sin_alpha * (sigma + C * sin(sigma) *
	        (cos(two_sigma_m) + C * cos(sigma) * (-1.0 + 2.0 * POW2(cos(two_sigma_m)))));
	lambda2 = r->lon + omega;
	g->lat = lat2;
	g->lon = lambda2;
	return G_SUCCESS;
}
开发者ID:Vlczech,项目名称:vtapi,代码行数:68,代码来源:lwspheroid.c

示例9: sp_fft_init

//static void fftInit(sp_fft *fft, int M)
void sp_fft_init(sp_fft *fft, int M)
{
    /* malloc and init cosine and bit reversed tables for a given size  */
    /* fft, ifft, rfft, rifft                                           */
    /* INPUTS                                                           */
    /*   M = log2 of fft size (ex M=10 for 1024 point fft)              */
    /* OUTPUTS                                                          */
    /*   private cosine and bit reversed tables                         */

    //SPFLOAT **UtblArray;
    //int16_t **BRLowArray;
    SPFLOAT *utbl;
    int16_t *BRLow;
    int i;

    //fft->FFT_table_1 = malloc(sizeof(SPFLOAT*) * 32);
    //fft->FFT_table_2 = malloc(sizeof(int16_t*) * 32);

    //for (i = 0; i < 32; i++) {
    //    ((SPFLOAT**) fft->FFT_table_1)[i] = (SPFLOAT*) NULL;
    //    ((int16_t**) fft->FFT_table_2)[i] = (int16_t*) NULL;
    //}

    //UtblArray = (SPFLOAT**) fft->FFT_table_1;
    //BRLowArray = (int16_t**) fft->FFT_table_2;

    /*** I did NOT test cases with M>27 ***/
    /* init cos table */
    utbl = (SPFLOAT*) malloc((POW2(M) / 4 + 1) * sizeof(SPFLOAT));
    fftCosInit(M, utbl);

    /*TODO: implement this later when we need complex FFT*/ 
    /* init bit reversed table for cmplx FFT */
    /*
    if (M > 1) {
      if (BRLowArray[M / 2] == NULL) {
        BRLowArray[M / 2] =
          (int16_t*) malloc(POW2(M / 2 - 1) * sizeof(int16_t));
        fftBRInit(M, BRLowArray[M / 2]);
      }
    }
    */

  /* init bit reversed table for real FFT */
     BRLow =
      (int16_t*) malloc(POW2((M - 1) / 2 - 1) * sizeof(int16_t));

    fftBRInit(M - 1, BRLow);
    fft->BRLow = BRLow;
    fft->utbl = utbl;

    //fft->FFT_max_size |= (1 << M);
}
开发者ID:eriser,项目名称:Soundpipe,代码行数:54,代码来源:sp_fft.c

示例10: mk_el

/* make a new extra list with specific capacity */
void mk_el(uint64 cap){
	printf("dc_mm : %s%8ld%s\n","start to generate extra chunks list of chunks with specific capacity ", 
	        POW2(cap), " Bytes.");
	struct slist * list_ptr;
	if(elm_table[cap])
		return;
	elm_table[cap] = (struct extra_list_manager *)malloc(sizeof(struct extra_list_manager));
	list_ptr = mm_pre_alloc(cap , DEFAULT_EXTRA);
	elm_table[cap]->idle_num = DEFAULT_EXTRA;
	elm_table[cap]->total_num = DEFAULT_EXTRA;
	elm_table[cap]->chunks_list = list_ptr;
	printf("dc_mm : %s%8ld%s\n","finish to generate extra chunks list of chunks with specific capacity ",
	        POW2(cap), " Bytes.");
}
开发者ID:gmsh,项目名称:dnscache,代码行数:15,代码来源:dc_mm.c

示例11: BAND_LOG

void EQ::recalculate_band_coefficients() {

#define BAND_LOG(m_f) (log((m_f)) / log(2.))

	for (int i = 0; i < band.size(); i++) {

		double octave_size;

		double frq = band[i].freq;

		if (i == 0) {

			octave_size = BAND_LOG(band[1].freq) - BAND_LOG(frq);
		} else if (i == (band.size() - 1)) {

			octave_size = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq);
		} else {

			double next = BAND_LOG(band[i + 1].freq) - BAND_LOG(frq);
			double prev = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq);
			octave_size = (next + prev) / 2.0;
		}

		double frq_l = round(frq / pow(2.0, octave_size / 2.0));

		double side_gain2 = POW2(Math_SQRT12);
		double th = 2.0 * Math_PI * frq / mix_rate;
		double th_l = 2.0 * Math_PI * frq_l / mix_rate;

		double c2a = side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) + side_gain2 - POW2(sin(th_l));

		double c2b = 2.0 * side_gain2 * POW2(cos(th_l)) + side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) - side_gain2 + POW2(sin(th_l));

		double c2c = 0.25 * side_gain2 * POW2(cos(th)) - 0.5 * side_gain2 * cos(th_l) * cos(th) + 0.25 * side_gain2 - 0.25 * POW2(sin(th_l));

		//printf("band %i, precoefs = %f,%f,%f\n",i,c2a,c2b,c2c);

		double r1, r2; //roots
		int roots = solve_quadratic(c2a, c2b, c2c, &r1, &r2);

		ERR_CONTINUE(roots == 0);

		band[i].c1 = 2.0 * ((0.5 - r1) / 2.0);
		band[i].c2 = 2.0 * r1;
		band[i].c3 = 2.0 * (0.5 + r1) * cos(th);
		//printf("band %i, coefs = %f,%f,%f\n",i,(float)bands[i].c1,(float)bands[i].c2,(float)bands[i].c3);
	}
}
开发者ID:Ranakhamis,项目名称:godot,代码行数:48,代码来源:eq.cpp

示例12: naHash_set

void naHash_set(naRef hash, naRef key, naRef val)
{
    HashRec* hr = REC(hash);
    if(!hr || hr->next >= POW2(hr->lgsz))
        hr = resize(PTR(hash).hash);
    hashset(hr, key, val);
}
开发者ID:andyross,项目名称:nasal,代码行数:7,代码来源:hash.c

示例13: CubicFilter

inline float CubicFilter(int x, int y, const int Radius)
{
	const int DatSize = POW2((Radius << 1) + 1);
	float *Dat = new float[DatSize];
	Cint2 Offset = {x-Radius, y-Radius};
	float Accum = 0.0f;
	int Denom = 0;

	int w = Bmp.TellWidth();
	int h = Bmp.TellHeight();

	for(int Cpt = 0; Cpt < DatSize; Cpt++){
		
		if(Offset.x >= 0 && Offset.x < w && 
		   Offset.y >= 0 && Offset.y < h){

			Accum += RGBMIXER(Offset.x, Offset.y);
			Denom++;
		}

		Offset.x++;
		if(Offset.x - x > Radius){
			Offset.x = x-Radius;
			Offset.y++;
		}

	}

	SAFE_DELETE_ARRAY(Dat);

	return Accum / (float)Denom;
}
开发者ID:SteveBeaupre,项目名称:Vortez3DEngine,代码行数:32,代码来源:HeightMap.cpp

示例14: select_extra

/* select a node frome the extra idle list */
void * select_extra(uint64 cap)
{
	void * ptr , * chunk_ptr;
	if(0 == elm_table[cap]->idle_num)
		return dc_alloc(POW2(cap));
	pthread_mutex_lock(extra_mutex[cap]);
	ptr = pop(elm_table[cap]->chunks_list);
	append(ptr,elm_table[cap]->chunks_list);
	--(elm_table[cap]->idle_num);
	extra_apply[cap]++;
	pthread_mutex_unlock(extra_mutex[cap]);
	chunk_ptr = (void *)((uint64 *)ptr + 1);
	printf("dc_mm : %s%8ld%s\n","select a specific capacity ", POW2(cap), 
	       " Bytes form extra chunks list.");
	return chunk_ptr;
}
开发者ID:gmsh,项目名称:dnscache,代码行数:17,代码来源:dc_mm.c

示例15: mm_init

void mm_init()
{
	int i = CHUNK_TYPE_NUM;
	while(i--){
		/* init all the pre-allocated chunks */
		chunks_manager_table[i] = (struct chunks_manager *)malloc(sizeof(struct chunks_manager));
		if(!chunks_manager_table[i]){
			printf("dc_mm : initilization failed!!!");	
			exit(1);
		}
		chunks_manager_table[i]->chunks_cap = SMALL+i;
		chunks_manager_table[i]->idle_num = chunks_num[i];
		chunks_manager_table[i]->idle_chunks = mm_pre_alloc((SMALL+i), chunks_num[i]);	
		chunks_manager_table[i]->alloced_chunks = mk_slist(malloc, chunks_num[i]);	
		printf("dc_mm : %s%8ld%s\n","chunks list and extra chunks list with specific capacity ",
		        POW2(SMALL + i), " Bytes has been initilized.");
		pre_alloc_mutex[i] = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(pre_alloc_mutex[i] , NULL);
		pre_alloc_apply[i] = pre_alloc_free[i] = 0;
	}
	int j = BIGGEST_CAP + 1;
	while(--j){
		extra_mutex[j] = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(extra_mutex[j] , NULL);
		extra_apply[j] = extra_free[j] = 0;
	}
	printf("dc_mm : %s\n","dns cache memory management modules has been initilized.");
	return;	
}
开发者ID:gmsh,项目名称:dnscache,代码行数:29,代码来源:dc_mm.c


注:本文中的POW2函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。