• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Factor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Factor

Node* Parser::Term()
{
	Node* pNode = Factor();
	EToken token = _scanner.Token();
	if (token == tMult || token == tDivide)
	{
		MultiNode* pMultiNode = new ProductNode(pNode);
		do
		{
			_scanner.Accept();
			Node* pRight = Factor();
			pMultiNode->AddChild (pRight, (token == tMult));
			token = _scanner.Token();
		}while (token == tMult || token == tDivide);
		pNode = pMultiNode;
	}
	return pNode;
	/*
	if (_scanner.Token() == tMult )
	{
		_scanner.Accept();
		Node* pRight = Term();
		pNode = new MultNode(pNode,pRight);
	}
	else if(_scanner.Token() == tDivide)
	{
		_scanner.Accept();
		Node* pRight = Term();
		pNode = new DivideNode (pNode, pRight );
	}
	return pNode;
	*/
}
开发者ID:Accordeur,项目名称:Calc,代码行数:33,代码来源:Parser.cpp


示例2: TermPrime

void TermPrime(void)
{
   switch (Symb.type) {
   case TIMES:
      /* T' -> * F BinOp T' */
      Symb = readLexem();
      Factor();
      Gener(BinOp, '*');      /* BinOp.dop = '*' */
      TermPrime();
      break;
   case DIVIDE:
      /* T' -> / F BinOp T' */
      Symb = readLexem();
      Factor();
      Gener(BinOp, '/');      /* BinOp.dop = '/' */
      TermPrime();
      break;
   case PLUS:
   case MINUS:
   case RPAR:
   case EOI:
      /* T' -> e */
      break;
   default:
      ExpansionError("T'", Symb.type);
   }
}
开发者ID:kkthx,项目名称:bi-pjp-sfe,代码行数:27,代码来源:parser.c


示例3: Item

//16.<项>—> <因子> [ *|/  <因子> ]
Val Item(){
	Val v1 = Factor();

	while (lookahead == mutiply || lookahead == div){
		int op = lookahead;
		if (op == mutiply) match(mutiply);
		else match(div);
		Val v2 = Factor();


		quadruples.push_back(Quadruple(sno++, op == mutiply ? mutiply : div, v1, v2, temp));
		//生成四元式
		/*printf("%3d (%c,", sno++, op == mutiply ? '*' : '/');
		
		if (v1.type == 1) printf("%s", GetNameByID(v1.value1));
		else if (v1.type == 0)  printf("%d", v1.value1);
		else if (v1.type == 2) printf("%lf", v1.value2);
		else printf("t%d", v1.value1);
		printf(",");
		if (v2.type == 1) printf("%s", GetNameByID(v2.value1));
		else if (v2.type == 0) printf("%d", v2.value1);
		else if (v2.type == 2) printf("%lf", v2.value2);
		else printf("t%d", v2.value1);
		printf(",t%d)\n", temp);*/

		v1.type = -1;
		v1.value1 = temp++;

	}
	return v1;
}
开发者ID:SherryPan123,项目名称:Compiler,代码行数:32,代码来源:语法分析.cpp


示例4: Term

result Term() {
    result lhs = Factor(), rhs;
    token op;
    if(lhs.error !=  ERR_NONE) {
        return lhs;
    }
    for(op = next_token(); op.type == TT_ASTERISK || op.type == TT_SLASH; op = next_token() ) { 
        rhs = Factor();
#ifdef DEBUG_1
        print_result("Term:lhs:", lhs);
        printf("Term:op:%d\n", op.type);
        print_result("Term:rhs:", rhs);
#endif
        if(rhs.error != ERR_NONE) {
            return rhs;
        }
        if(op.type == TT_ASTERISK) {
            lhs.value *= rhs.value;
        }
        else if(op.type == TT_SLASH) {
            if(rhs.value != 0) {
                lhs.value /= rhs.value;
            }
            else {
                return make_result(ERR_DIVISION_BY_ZERO, 0); 
            }
        }
        else {
            return make_result(ERR_UNEXPECTED_TOKEN, 0);
        }
    }
    rollback();
    return make_result(ERR_NONE, lhs.value);
}
开发者ID:melentyev,项目名称:spbu-homework,代码行数:34,代码来源:expressinons.c


示例5: switch

 void Polynomial<Degree>::getSolutions(const double& c,std::vector<double>& roots,const double& EPS) const {
   double r[4][2];
   int rCount=0;
   roots.clear();
   switch(Degree){
     case 1:
       rCount=Factor(coefficients[1],coefficients[0]-c,r,EPS);
       break;
     case 2:
       rCount=Factor(coefficients[2],coefficients[1],coefficients[0]-c,r,EPS);
       break;
     case 3:
       rCount=Factor(coefficients[3],coefficients[2],coefficients[1],coefficients[0]-c,r,EPS);
       break;
       //	case 4:
       //		rCount=Factor(coefficients[4],coefficients[3],coefficients[2],coefficients[1],coefficients[0]-c,r,EPS);
       //		break;
     default:
       printf("Can't solve polynomial of degree: %d\n",Degree);
   }
   for(int i=0;i<rCount;i++){
     if(fabs(r[i][1])<=EPS){
       roots.push_back(r[i][0]);
       //printf("%d] %f\t%f\n",i,r[i][0],(*this)(r[i][0])-c);
     }
   }
 }
开发者ID:hitsjt,项目名称:StanfordPCL,代码行数:27,代码来源:polynomial.hpp


示例6: Factor

void HAK::construct() {
    // Create outer beliefs
    if( props.verbose >= 3 )
        cerr << "Constructing outer beliefs" << endl;
    _Qa.clear();
    _Qa.reserve(nrORs());
    for( size_t alpha = 0; alpha < nrORs(); alpha++ )
        _Qa.push_back( Factor( OR(alpha) ) );

    // Create inner beliefs
    if( props.verbose >= 3 )
        cerr << "Constructing inner beliefs" << endl;
    _Qb.clear();
    _Qb.reserve(nrIRs());
    for( size_t beta = 0; beta < nrIRs(); beta++ )
        _Qb.push_back( Factor( IR(beta) ) );

    // Create messages
    if( props.verbose >= 3 )
        cerr << "Constructing messages" << endl;
    _muab.clear();
    _muab.reserve( nrORs() );
    _muba.clear();
    _muba.reserve( nrORs() );
    for( size_t alpha = 0; alpha < nrORs(); alpha++ ) {
        _muab.push_back( vector<Factor>() );
        _muba.push_back( vector<Factor>() );
        _muab[alpha].reserve( nbOR(alpha).size() );
        _muba[alpha].reserve( nbOR(alpha).size() );
        foreach( const Neighbor &beta, nbOR(alpha) ) {
            _muab[alpha].push_back( Factor( IR(beta) ) );
            _muba[alpha].push_back( Factor( IR(beta) ) );
        }
    }
开发者ID:Nick11,项目名称:V3DSfMToolkit,代码行数:34,代码来源:hak.cpp


示例7: print

bool syntaxparser::TermPrime(){
	bool bTermPrime = false;
	if (lexeme == "*"){
		print();
		cout<<endl;
		Lexer();
		if(displayFlag){
			cout << "<TermPrime> ::= *<Factor><TermPrime>" << endl;
			printproduction("<TermPrime> ::= *<Factor><TermPrime>");
		}
		Factor();
		project3.gen_inst("MUL","-999");

		string type1, type2;

			type1 = project3.returnSymbolType(2);
			type2 = project3.returnSymbolType(3);

			if(type1 == "boolean")
				error("Cannot perform '*' on boolean");
			if (type2 == "boolean")
				error("Cannot perform '*' on boolean");

		TermPrime();	
		bTermPrime = true;		
	}
	else if (lexeme == "/"){
		print();
		cout<<endl;
		Lexer();
		if(displayFlag){
			cout << "<TermPrime> ::= /<Term><FactorPrime>" << endl;
			printproduction("<TermPrime> ::= /<Term><FactorPrime>");
		}
		bTermPrime = true;
		Factor();
		project3.gen_inst("DIV", "-999");

		string type1, type2;

			type1 = project3.returnSymbolType(2);
			type2 = project3.returnSymbolType(3);

			if(type1 == "boolean")
				error("Cannot perform '/' on boolean");
			if (type2 == "boolean")
				error("Cannot perform '/' on boolean");

		TermPrime();
	}
	else{
		bTermPrime = true;
		if(displayFlag){
			cout << "<TermPrime> ::= epsilon" << endl;
			printproduction("<TermPrime> ::= epsilon");
		}
	}
	return bTermPrime;
}
开发者ID:fullerton323,项目名称:compiler,代码行数:59,代码来源:syntaxparser.cpp


示例8: Factor

// Solution taken from: http://mathworld.wolfram.com/QuarticEquation.html
// and http://www.csit.fsu.edu/~burkardt/f_src/subpak/subpak.f90
int Factor(double a4,double a3,double a2,double a1,double a0,double roots[4][2],const double& EPS){
	double R[2],D[2],E[2],R2[2];

	if(fabs(a4)<EPS){return Factor(a3,a2,a1,a0,roots,EPS);}
	a3/=a4;
	a2/=a4;
	a1/=a4;
	a0/=a4;

	Factor(1.0,-a2,a3*a1-4.0*a0,-a3*a3*a0+4.0*a2*a0-a1*a1,roots,EPS);

	R2[0]=a3*a3/4.0-a2+roots[0][0];
	R2[1]=0;
	Sqrt(R2,R);
	if(fabs(R[0])>10e-8){
		double temp1[2],temp2[2];
		double p1[2],p2[2];

		p1[0]=a3*a3*0.75-2.0*a2-R2[0];
		p1[1]=0;

		temp2[0]=((4.0*a3*a2-8.0*a1-a3*a3*a3)/4.0);
		temp2[1]=0;
		Divide(temp2,R,p2);

		Add     (p1,p2,temp1);
		Subtract(p1,p2,temp2);

		Sqrt(temp1,D);
		Sqrt(temp2,E);
	}
	else{
		R[0]=R[1]=0;
		double temp1[2],temp2[2];
		temp1[0]=roots[0][0]*roots[0][0]-4.0*a0;
		temp1[1]=0;
		Sqrt(temp1,temp2);
		temp1[0]=a3*a3*0.75-2.0*a2+2.0*temp2[0];
		temp1[1]=                  2.0*temp2[1];
		Sqrt(temp1,D);
		temp1[0]=a3*a3*0.75-2.0*a2-2.0*temp2[0];
		temp1[1]=                 -2.0*temp2[1];
		Sqrt(temp1,E);
	}

	roots[0][0]=-a3/4.0+R[0]/2.0+D[0]/2.0;
	roots[0][1]=        R[1]/2.0+D[1]/2.0;

	roots[1][0]=-a3/4.0+R[0]/2.0-D[0]/2.0;
	roots[1][1]=        R[1]/2.0-D[1]/2.0;

	roots[2][0]=-a3/4.0-R[0]/2.0+E[0]/2.0;
	roots[2][1]=       -R[1]/2.0+E[1]/2.0;

	roots[3][0]=-a3/4.0-R[0]/2.0-E[0]/2.0;
	roots[3][1]=       -R[1]/2.0-E[1]/2.0;
	return 4;
}
开发者ID:Benzlxs,项目名称:PRSM,代码行数:60,代码来源:Factor.cpp


示例9: Term

void Term()
{
	Factor();
	while(!strcmp(string[TokenCounter],"*"))
	{
		MulOp();
		Factor();
	}
}
开发者ID:fadyfares7,项目名称:TinyLanguage_Scanner_And_Parser-,代码行数:9,代码来源:parser.c


示例10: Factor

Factor LC::belief (const VarSet &ns) const {
    if( ns.size() == 0 )
        return Factor();
    else if( ns.size() == 1 )
        return beliefV( findVar( *(ns.begin()) ) );
    else {
        DAI_THROW(BELIEF_NOT_AVAILABLE);
        return Factor();
    }
}
开发者ID:afbarnard,项目名称:libdai,代码行数:10,代码来源:lc.cpp


示例11: Factor

void Parser::Term(int &type) {
    int type1, op;
    Factor(type);
    while (la->kind == 7 || la->kind == 8) {
        MulOp(op);
        Factor(type1);
        if (type != integer || type1 != integer)
            Err(L"integer type expected");
        gen->Emit(op);
    }
}
开发者ID:Newky,项目名称:3rdYear,代码行数:11,代码来源:Parser.cpp


示例12: FirstFactor

void FirstFactor() {
  switch(Look) {
    case '+': 
      Match('+');
      Factor();
      break;
    case '-':
      NegFactor();
      break;
    default: Factor();
  }
}
开发者ID:A-deLuna,项目名称:crenshaw-c-x86_64-compiler,代码行数:12,代码来源:main.c


示例13: Weight

// This code has been copied from bp.cpp, except where comments indicate TRWBP-specific behaviour
Prob TRWBP::calcIncomingMessageProduct( size_t I, bool without_i, size_t i ) const {
    Real c_I = Weight(I); // TRWBP: c_I

    Factor Fprod( factor(I) );
    Prob &prod = Fprod.p();
    if( props.logdomain ) {
        prod.takeLog();
        prod /= c_I; // TRWBP
    } else
        prod ^= (1.0 / c_I); // TRWBP

    // Calculate product of incoming messages and factor I
    bforeach( const Neighbor &j, nbF(I) )
        if( !(without_i && (j == i)) ) {
            const Var &v_j = var(j);
            // prod_j will be the product of messages coming into j
            // TRWBP: corresponds to messages n_jI
            Prob prod_j( v_j.states(), props.logdomain ? 0.0 : 1.0 );
            bforeach( const Neighbor &J, nbV(j) ) {
                Real c_J = Weight(J);  // TRWBP
                if( J != I ) { // for all J in nb(j) \ I
                    if( props.logdomain )
                        prod_j += message( j, J.iter ) * c_J;
                    else
                        prod_j *= message( j, J.iter ) ^ c_J;
                } else if( c_J != 1.0 ) { // TRWBP: multiply by m_Ij^(c_I-1)
                    if( props.logdomain )
                        prod_j += message( j, J.iter ) * (c_J - 1.0);
                    else
                        prod_j *= message( j, J.iter ) ^ (c_J - 1.0);
                }
            }

            // multiply prod with prod_j
            if( !DAI_TRWBP_FAST ) {
                // UNOPTIMIZED (SIMPLE TO READ, BUT SLOW) VERSION
                if( props.logdomain )
                    Fprod += Factor( v_j, prod_j );
                else
                    Fprod *= Factor( v_j, prod_j );
            } else {
                // OPTIMIZED VERSION
                size_t _I = j.dual;
                // ind is the precalculated IndexFor(j,I) i.e. to x_I == k corresponds x_j == ind[k]
                const ind_t &ind = index(j, _I);

                for( size_t r = 0; r < prod.size(); ++r )
                    if( props.logdomain )
                        prod.set( r, prod[r] + prod_j[ind[r]] );
                    else
                        prod.set( r, prod[r] * prod_j[ind[r]] );
            }
        }
开发者ID:DerThorsten,项目名称:libdai,代码行数:54,代码来源:trwbp.cpp


示例14: switch

Expr *TermPrimed(Expr *du)
{
   switch (Symb.type) {
   case TIMES:
      Symb = readLexem();
      return TermPrimed(new Bop(Times, du, Factor()));
   case DIVIDE:
      Symb = readLexem();
      return ExpressionPrimed(new Bop(Divide, du, Factor()));
   default:
      return du;
   }
}
开发者ID:kkthx,项目名称:bi-pjp-sfe,代码行数:13,代码来源:parser.cpp


示例15: Factor

void CParser::Term2()
{
	Factor();
	while (true)
	{
		switch (mLookahead)
		{
			case RAISE: Match(RAISE); Factor(); AddToken(opRaise); break;
			case '^': Match('^'); Factor(); AddToken(opRaise); break;
			default: return;
		}
	}
} // CParser::Term2
开发者ID:ModeenF,项目名称:OpenSumIt,代码行数:13,代码来源:parser.cpp


示例16: nrVars

void ExactInf::construct() {
    // clear variable beliefs and reserve space
    _beliefsV.clear();
    _beliefsV.reserve( nrVars() );
    for( size_t i = 0; i < nrVars(); i++ )
        _beliefsV.push_back( Factor( var(i) ) );

    // clear factor beliefs and reserve space
    _beliefsF.clear();
    _beliefsF.reserve( nrFactors() );
    for( size_t I = 0; I < nrFactors(); I++ )
        _beliefsF.push_back( Factor( factor(I).vars() ) );
}
开发者ID:alucchi,项目名称:structured_prediction_for_segmentation,代码行数:13,代码来源:exactinf.cpp


示例17: Term

string Parser::Term() {

    _message.print(DBUG, "PARSER: In Term()\n");

    //Factor, { ( “*” | ”/” | “%” ), Factor }

    static tokenType firstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1};

    static tokenType followSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_LESS_EQ, SYM_LESS, SYM_GREATER_EQ, SYM_GREATER, SYM_EQUAL, SYM_NOT_EQ, SYM_AND, SYM_OR, SYM_ASSIGN, SYM_SEMICOLON, SYM_OPEN, SYM_SQ_OPEN, SYM_COMMA, SYM_CLOSE, (tokenType) - 1};

    string type, type1;

    if ( synchronized(firstSet, followSet, "Expected Term") ) {

        type = Factor();

        while ( _lookAhead.getTokenType() == SYM_MUL ||
                _lookAhead.getTokenType() == SYM_DIV ||
                _lookAhead.getTokenType() == SYM_MOD ) {
            bool isModOperation = false;
            if ( _lookAhead.getTokenType() == SYM_MUL) {
                match(SYM_MUL);
            } else if(_lookAhead.getTokenType() == SYM_DIV) {
                match(SYM_DIV);
            } else if(_lookAhead.getTokenType() == SYM_MOD) {
                match(SYM_MOD);
                isModOperation = true;
            }

            type1 = Factor();

            if((type == "f" && type1 == "i") ||
                    (type == "f" && type1 == "f") ||
                    (type == "i" && type1 == "f")) {
                type = "f";
                if (isModOperation) {
                    type = "i";
                }
            } else if(type == "i" && type1 == "i") {
                type = "i";
            } else {
                _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Incompatible operation", _lookAhead.getRow() , _lookAhead.getCol());
            }
        }
    }
    _message.print(DBUG, "PARSER: End of Term()\n");
    return type;
}
开发者ID:roshangautam,项目名称:cmm-compiler,代码行数:48,代码来源:Parser.cpp


示例18: var

Real LC::CalcCavityDist (size_t i, const std::string &name, const PropertySet &opts) {
    Factor Bi;
    Real maxdiff = 0;

    if( props.verbose >= 2 )
        cerr << "Initing cavity " << var(i) << "(" << delta(i).size() << " vars, " << delta(i).nrStates() << " states)" << endl;

    if( props.cavity == Properties::CavityType::UNIFORM )
        Bi = Factor(delta(i));
    else {
        InfAlg *cav = newInfAlg( name, *this, opts );
        cav->makeCavity( i );

        if( props.cavity == Properties::CavityType::FULL )
            Bi = calcMarginal( *cav, cav->fg().delta(i), props.reinit );
        else if( props.cavity == Properties::CavityType::PAIR ) {
            vector<Factor> pairbeliefs = calcPairBeliefs( *cav, cav->fg().delta(i), props.reinit, false );
            for( size_t ij = 0; ij < pairbeliefs.size(); ij++ )
                Bi *= pairbeliefs[ij];
        } else if( props.cavity == Properties::CavityType::PAIR2 ) {
            vector<Factor> pairbeliefs = calcPairBeliefs( *cav, cav->fg().delta(i), props.reinit, true );
            for( size_t ij = 0; ij < pairbeliefs.size(); ij++ )
                Bi *= pairbeliefs[ij];
        }
        maxdiff = cav->maxDiff();
        delete cav;
    }
    Bi.normalize();
    _cavitydists[i] = Bi;

    return maxdiff;
}
开发者ID:afbarnard,项目名称:libdai,代码行数:32,代码来源:lc.cpp


示例19: if

bool Parser::TPrime()
{
	bool div = false;
	if ("*" == lex) {
		L.getTokLex(tok,lex);
	} else if ("/" == lex) {
		div = true;
		L.getTokLex(tok,lex);
	} else {
//		std::cout << "TPrime => null\n";
		return true;
	}
	
	if (!Factor()) return false;
	
	if (!TPrime()) return false;

	if (div) {
		assembly.push_back(icode(a_line, "DIV"));
		++a_line;
	} else {
		assembly.push_back(icode(a_line, "MUL"));
		++a_line;
	}

//	if (div) {
//		std::cout << "TPrime => / Factor TPrime\n";
//	} else {
//		std::cout << "TPrime => * Factor TPrime\n";
//	}
	return true;
}
开发者ID:123Phil,项目名称:Compiler,代码行数:32,代码来源:Parser.cpp


示例20: bforeach

void FactorGraph::makeCavity( size_t i, bool backup ) {
  // fills all Factors that include var(i) with ones
  std::map<size_t,Factor> newFacs;
  bforeach( const dai::Neighbor &I, nbV(i) ) // for all neighboring factors I of i
    newFacs[I] = Factor(factor(I).nodes());
  setFactors( newFacs, backup );
}
开发者ID:ushadow,项目名称:pdbntk,代码行数:7,代码来源:factor_graph.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Factorial函数代码示例发布时间:2022-05-30
下一篇:
C++ Face函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap