Beispiel #1
0
int _atoi(char *str)
{
    int len = strlen(str);
    int i;
    int radix = 0;
    int result = 0;

    if(str[0] == '-') {
        radix = _pow(len-2);

        for(i=1; i<=len; i++) {
            result += (str[i] - '0') * radix;
            radix /= 10;
        }

        result = -result;
    } else {
        radix = _pow(len-1);

        for(i=0; i<=len; i++) {
            result += (str[i] - '0') * radix;
            radix /= 10;
        }
    }

    return -result/50;
}
Beispiel #2
0
//下壁の吸収境界
void NsFDTD::absorbing_down(){

	double u1, u2;
	double w_b  = w_s*DT_S/2;
	double k_b  = k_s*H_S/2;
	double kx_b = kx_s*H_S/2;
	double ky_b = ky_s*H_S/2;

	for(int i=1; i<mField->getNx()-1; i++){

		u1 = tan(w_b/n_s[index(i,mField->getNx()-1)]) / tan(k_b);
		u2 = 2 * _pow(sin(w_b/n_s[index(i,mField->getNx()-1)]), 2) / _pow(sin(ky_b),2) * (1 - tan(kx_b)/tan(k_b));

		if(i==1 || i==mField->getNx()-2)	//四隅の横は一次元吸収境界
			phi[index(i,mField->getNx()-1, +1)] = phi[index(i,mField->getNx()-2, 0)] + (1- u1)/(1+u1)*(phi[index(i,mField->getNx()-1, 0)] - phi[index(i,mField->getNx()-2, +1)]);



		else				//二次元吸収境界
			phi[index(i,mField->getNx()-1, +1)] = -phi[index(i,mField->getNx()-2, -1)] 
			                      - (1-u1)/(1+u1)*(phi[index(i,mField->getNx()-1, -1)]+phi[index(i,mField->getNx()-2, +1)]) 
							      +     2/(1+u1)*(phi[index(i,mField->getNx()-1,  0)]+phi[index(i,mField->getNx()-2,  0)]) 
								  + u2*u2/(1+u1)/2*( Dx2(phi, i,mField->getNx()-1, 0) + Dx2(phi, i,mField->getNx()-2, 0)	 );
													 //  dx^2 φn     +   dx^2 φb
	}		
}
double wurzel (double start, double x, double n){  
  double temp = start - (((_pow(start,n)) - x) / (n * _pow(start,n-1)));

  if (((temp-start)*-1) <= e){
    return temp;
  }
  return wurzel(temp,x,n);
}
Beispiel #4
0
Datei: sin.c Projekt: cjxgm/lanos
float sin(float x)
{
    while (x < -PI) x += 2*PI;
    while (x >= PI) x -= 2*PI;

    return x - _pow(x, 3) / _fac(3)
           + _pow(x, 5) / _fac(5)
           - _pow(x, 7) / _fac(7);
}
Beispiel #5
0
inline T _pow(T arg, int exp)
{
	if(exp > 0)
	{
		return _pow(arg,exp-1)*arg;
	}
	else if(exp == 0)
	{
		return static_cast<T>(1);
	}
	else
	{
		return _pow(static_cast<T>(1)/arg,exp);
	}
}
Beispiel #6
0
static
Value *
eval(const Ast *expr) {
	switch(expr->class) {
	case N_CALL:
		return call(expr);
	case N_ASSIGNMENT:
		return assignment(expr);
	case N_IDENTIFIER:
		return identifier(expr);
	case N_NEG:
		return _neg(expr);
	case N_NOT:
		return _not(expr);
	case N_EQ:
		return _eq(expr);
	case N_NEQ:
		return _neq(expr);
	case N_AND:
		return _and(expr);
	case N_IOR:
		return _ior(expr);
	case N_XOR:
		return _neq(expr); // alias
	case N_LT:
		return _lt(expr);
	case N_LE:
		return _le(expr);
	case N_GE:
		return _ge(expr);
	case N_GT:
		return _gt(expr);
	case N_ADD:
		return _add(expr);
	case N_SUB:
		return _sub(expr);
	case N_MUL:
		return _mul(expr);
	case N_DIV:
		return _div(expr);
	case N_POW:
		return _pow(expr);
	case N_MOD:
		return _mod(expr);
	case N_BOOLEAN:
		return _bool(expr);
	case N_INTEGER:
		return _int(expr);
	case N_FLOAT:
		return _float(expr);
	case N_STRING:
		return _string(expr);
	case N_SET:
		return _set(expr);
	case N_R:
		return _relation(expr);
	}
printf("EVALFAIL %d ", expr->class); pn(expr);
	assert(false && "should not be reached");
}
Beispiel #7
0
void NsFDTD::Mie_Cylinder_Incidence(){
	//中心の円に,散乱波発生
	for(int i=0; i<mField->getNx(); i++)
		for(int j=0; j<mField->getNx(); j++)	
	//		if((i-mField->getNx()/2)*(i-mField->getNx()/2) + (j-mField->getNx()/2)*(j-mField->getNx()/2) <= lambda_s*lambda_s)
				phi[index(i,j, +1)] += (1-exp(-0.01*time*time))*(1/_pow(n_s[index(i,j)], 2) - 1) * ( sin(k_s*i - w_s*(time + DT_S) ) + sin(k_s*i - w_s*(time - DT_S)) - 2*sin(k_s*i - w_s*time)); 
	
}
double _zweierfolge(double epsilon, double a, int n){
	double ret;
	
	ret = _pow(2/(double)(2*n-1),2) * (2*n*n-2*n+1) + ((a-1)/((double)n+1));
	
	if(_abs(ret-a)<epsilon)
		return ret;
	
	return _zweierfolge(epsilon, ret, n+1);
}
Beispiel #9
0
//散乱波の計算
void Solver::scatteredWave(complex<double> *p){
	double rad = wave_angle*M_PI/180;	//ラジアン変換
	double _cos = cos(rad), _sin = sin(rad);	//毎回計算すると時間かかりそうだから,代入しておく

	for(int i=mField->getNpml(); i<mField->getNpx(); i++){
		for(int j=mField->getNpml(); j<mField->getNpy(); j++){
			if( N_S(i,j) == 1.0 ) continue;		//屈折率が1なら散乱は起きない
			double ikx = k_s*(i*_cos + j*_sin);
			p[index(i,j, +1)] += ray_coef*(1/_pow(N_S(i,j), 2)-1)
				                    *(polar(1.0, ikx-w_s*(time+DT_S))+polar(1.0, ikx-w_s*(time-DT_S))-2.0*polar(1.0, ikx-w_s*time)); 
		}
	}
}
Beispiel #10
0
/**上下の壁のNS吸収境界
** 適用配列
** 適用するy座標
** 上か下か
*/
void Solver::absorbing_nsTB(complex<double> *p, int Y, enum DIRECT offset){
	double kx_s = 1/sqrt(sqrt(2.0)) * k_s;
	double ky_s = sqrt(1 - 1/sqrt(2.0) ) * k_s;
	double u1, u2;
	double w_b  = w_s*DT_S/2;
	double k_b  = k_s*H_S/2;
	double kx_b = kx_s*H_S/2;
	double ky_b = ky_s*H_S/2;

	for(int i=1; i<mField->getNx()-1; i++){
		u1 = tan(w_b/n_s[index(i,Y)]) / tan(k_b);
		u2 = 2 * _pow(sin(w_b/n_s[index(i,Y)]), 2) / _pow(sin(ky_b),2) * (1 - tan(kx_b)/tan(k_b));

		if(i==1 || i==mField->getNx()-2)	//四隅の横は一次元吸収境界
			p[index(i,Y, +1)]    = p[index(i,Y+offset, 0)]    + (1- u1)/(1+u1)*(p[index(i,Y, 0)] - p[index(i,Y+offset, +1)]);

		else				//二次元吸収境界
			p[index(i,Y, +1)]  = -p[index(i,Y+offset, -1)]    
								  - (1-u1)/(1+u1)*(p[index(i,Y, -1)] + p[index(i,Y+offset, +1)]) 
							      +     2/(1+u1)*(p[index(i,Y, 0)]  + p[index(i,Y+offset, 0)])     
								  + u2*u2/(1+u1)/2*( Dx2(p, i,Y, 0)   + Dx2(p, i,Y+offset, 0) 	);
												  //  dx^2 φn     +   dx^2 φb
	}		
}
Beispiel #11
0
/**左右の壁のNS吸収境界
** 適用配列
** 適用するx座標
** 右か左か
*/
void Solver::absorbing_nsRL(complex<double> *p, int X, enum DIRECT offset){
	double kx_s = 1/sqrt(sqrt(2.0)) * k_s;
	double ky_s = sqrt(1 - 1/sqrt(2.0) ) * k_s;
	double u1, u2;
	double w_b  = w_s*DT_S/2;
	double k_b  = k_s*H_S/2;
	double kx_b = kx_s*H_S/2;
	double ky_b = ky_s*H_S/2;

	for(int j=1; j<mField->getNy()-1; j++){
		u1 = tan(w_b/n_s[index(X,j)]) / tan(k_b);
		u2 = 2 * _pow(sin(w_b/N_S(X,j)), 2) / _pow(sin(ky_b),2) * (1 - tan(kx_b)/tan(k_b));

		if(j == 1 || j == mField->getNy()-2)		// 四隅の横は一次元吸収境界
			p[index(X,j, +1)] = p[index(X+offset,j, 0)] + (1- u1)/(1+u1)*(p[index(X,j, 0)] - p[index(X+offset,j, +1)]);

		else						//それ以外は二次元吸収境界
			p[index(X,j, +1)] = - p[index(X+offset,j, -1)] 
								- (1-u1)/(1+u1)*(p[index(X,j, -1)] + p[index(X+offset,j, +1)]) 
								+     2/(1+u1)*(p[index(X,j,  0)] + p[index(X+offset,j,  0)]) 
								+ u2*u2/(1+u1)/2*( Dy2(p, X,j, 0)   +  Dy2(p, X+offset,j, 0)	);
												        //  dy^2 φn     +   dy^2 φb
	}
}
Beispiel #12
0
void soulLand()
{
	nodeTree *oldRoot = myTree->root;
	myTree->root = new nodeTree();
	myTree->root->balance = 0;
	myTree->root->exp = 0;
	myTree->root->key = 777;
	myTree->root->level = 7;
	myTree->root->pLeft = NULL;
	myTree->root->pRight = NULL;

	insertNLR(oldRoot);
	isSoulLand = 1;
	isJack = 1;
	if (_pow(2, getHeight(myTree->root)) - 1 == getCount(myTree->root))
		incLevel(myTree->root);
}
Beispiel #13
0
void NsFDTD::field(){
	//屈折率の設定
	//計算用定数の設定
	kx_s = 1/sqrt(sqrt(2.0)) * k_s;
	ky_s = sqrt(1 - 1/sqrt(2.0) ) * k_s;

	double sin2_kx = pow(sin(kx_s*H_S/2), 2);
	double sin2_ky = pow(sin(ky_s*H_S/2), 2);
	double sin2_k  = pow(sin(k_s *H_S/2), 2);
	r_s = (sin2_kx + sin2_ky - sin2_k)/(4*sin2_kx*sin2_ky);  //(1-γ0)/2

	double w_b  = w_s*DT_S/2;
	double k_b  = k_s*H_S/2;
	//double kx_b = k_b * cos(PI/4);
	//double ky_b = k_b * sin(PI/4)

	for(int i=0; i<mField->getNx(); i++)
		for(int j=0; j<mField->getNy();j++)
			np[index(i,j)] = _pow(sin(w_b/n_s[index(i,j)]) / sin(k_b),2);
}
Beispiel #14
0
REAL _pow2(REAL a, REAL b, QByteArray &error)
{
    return _ln(a, b, error) * _pow(a, b, error);
}
Beispiel #15
0
REAL _pow1(REAL a, REAL b, QByteArray &error)
{
    return (b * _pow(a, b - ONE, error));
}