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


C++ Divide函数代码示例

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


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

示例1: main

int main()
{
	try
	{
		std::cout << Divide(5, 2) << std::endl;
		std::cout << Divide(10, 0) << std::endl;
		std::cout << Divide(3, 3) << std::endl;
	}
	catch (const std::invalid_argument& e)
	{
		std::cout << "Caught exception: " << e.what() << std::endl;
	}

	return 0;
}
开发者ID:MidoriYakumo,项目名称:ModernCpp,代码行数:15,代码来源:try-catch-throw1.cpp

示例2: VirtualSpace_Release

void VirtualSpace_Release(uint32_t* logAddrToRealease, uint32_t nbPages)
{
	FreeSpace* nextFS = VirtualSpace_GetNextFreeSpace(logAddrToRealease);
	FreeSpace* prevFS = VirtualSpace_GetPrevious(nextFS);
	uint8_t createNewFS = 1;
	if((*nextFS).addrSpace==logAddrToRealease+nbPages*PAGE_SIZE)
	{
		(*nextFS).addrSpace = logAddrToRealease;
		(*nextFS).nbPagesFree += nbPages;

		createNewFS = 0;
	}
	
	if((*prevFS).addrSpace+(*prevFS).nbPagesFree*PAGE_SIZE==logAddrToRealease)
	{
		(*prevFS).nbPagesFree += nbPages;

		createNewFS = 0;
	}

	if(createNewFS)
	{		
		uint32_t nbMiniFrames;
		uint32_t mod;
		Divide(	sizeof(FreeSpace),
				MINI_FRAMES_SIZE_OF_A_FRAME+1,
				&nbMiniFrames,&mod);
		FreeSpace* newFS = (FreeSpace*)Mini_Alloc(nbMiniFrames,0);
		(*newFS).nbPagesFree = nbPages;
		(*newFS).addrSpace = logAddrToRealease;
		(*newFS).ptNextFreeSpace = nextFS;
		(*prevFS).ptNextFreeSpace = newFS;
	}

}
开发者ID:kar1m,项目名称:RaspberryPi,代码行数:35,代码来源:vMem_Alloc.c

示例3: CreateSphere

// Creates a sphere
Mesh* CreateSphere(int subdivisions)
{
    nextIndex = 0;
	// TODO: calc how many items in the arrays we need
    vertices = new Vertex[100000];
	vertexCurrentIndex = 0;
	indices = new USHORT[100000];
	indexCurrentIndex = 0;

    AddBaseTriangle(CreateVector(0, 0, 1), CreateVector(1, 0, 0), CreateVector(0, 1, 0));
    AddBaseTriangle(CreateVector(1, 0, 0), CreateVector(0, 0, -1), CreateVector(0, 1, 0));
    AddBaseTriangle(CreateVector(0, 0, -1), CreateVector(-1, 0, 0), CreateVector(0, 1, 0));
    AddBaseTriangle(CreateVector(-1, 0, 0), CreateVector(0, 0, 1), CreateVector(0, 1, 0));
    AddBaseTriangle(CreateVector(1, 0, 0), CreateVector(0, 0, 1), CreateVector(0, -1, 0));
    AddBaseTriangle(CreateVector(0, 0, -1), CreateVector(1, 0, 0), CreateVector(0, -1, 0));
    AddBaseTriangle(CreateVector(-1, 0, 0), CreateVector(0, 0, -1), CreateVector(0, -1, 0));
    AddBaseTriangle(CreateVector(0, 0, 1), CreateVector(-1, 0, 0), CreateVector(0, -1, 0));

    for (int division = 1; division < subdivisions; division++) Divide();

	Mesh* mesh = new Mesh();
	mesh->Set(vertices, vertexCurrentIndex, indices, indexCurrentIndex);

	// Free allocated arrays
	delete [] vertices;
	delete [] indices;

	return mesh;
}
开发者ID:AnthonyNystrom,项目名称:NuGenBioChemDX,代码行数:30,代码来源:Sphere.cpp

示例4: main

int main()
{
	int x;
	int start=0,end=100;
	int y=(start+end)/2;
	printf("*****************************************************************\n");
	printf("Enter the number corresponding to the desired pay rate or action:\n");
	printf("a) add\t\t\ts) subtract\n");
	printf("m) multiply\t\td) divide\n");
	printf("q) quit\n");
	printf("*****************************************************************\n");
	x=getchar();
	switch(x)
	{
		case 'a':
			Add();
			break;
		case 's':
			Subtract();
			break;
		case 'm':
			Mutliply();
			break;
		case 'd':
			Divide();
			break;
		case 'q':
			printf("Bye~~~~~~\n");
			break;
	}
}
开发者ID:gaowanchen,项目名称:C_primer_plus_exercise,代码行数:31,代码来源:ex8.11.c

示例5: efficiencyBinomialErrors

void efficiencyBinomialErrors()
{
  printf("\n Get the binomial errors for efficiencies\n\n");

  auto h_num = new TH1D("h_num", "h_num", nbins, 0, nbins);
  auto h_den = new TH1D("h_den", "h_den", nbins, 0, nbins);

  for (int i=0; i<nbins; i++)
    {
      h_num->SetBinContent(i+1, n_num[i]);
      h_den->SetBinContent(i+1, n_den[i]);
    }

  auto graph = new TGraphAsymmErrors();

  graph->Divide(h_num, h_den, "cl=0.683 b(1,1) mode");

  auto canvas = new TCanvas("canvas", "canvas");

  graph->SetMarkerStyle(kFullCircle);

  graph->Draw("apz");

  graph->Print();
}
开发者ID:piedraj,项目名称:AnalysisCMS,代码行数:25,代码来源:efficiencyBinomialErrors.C

示例6: ShortestDistance

void M2MFstAligner::expectation( ){
  /*
    Here we compute the arc posteriors.  This routine is almost 
    fun to implement in the FST paradigm.
  */
  for( unsigned int i=0; i<fsas.size(); i++ ){
    //Compute Forward and Backward probabilities
    ShortestDistance( fsas.at(i), &alpha );
    ShortestDistance( fsas.at(i), &beta, true );

    //Compute the normalized Gamma probabilities and 
    // update our running tally
    for( StateIterator<VectorFst<LogArc> > siter(fsas.at(i)); !siter.Done(); siter.Next() ){
      LogArc::StateId q = siter.Value();
      for( ArcIterator<VectorFst<LogArc> > aiter(fsas.at(i),q); !aiter.Done(); aiter.Next() ){
	const LogArc&      arc = aiter.Value();
	const LogWeight& gamma = Divide(Times(Times(alpha[q], arc.weight), beta[arc.nextstate]), beta[0]); 
	//Check for any BadValue results, otherwise add to the tally.
        //We call this 'prev_alignment_model' which may seem misleading, but
        // this conventions leads to 'alignment_model' being the final version.
	if( gamma.Value()==gamma.Value() ){
	  prev_alignment_model[arc.ilabel] = Plus(prev_alignment_model[arc.ilabel], gamma);
	  total = Plus(total, gamma);
	}
      }
    }
    alpha.clear();
    beta.clear();
  }
}
开发者ID:Joda89,项目名称:g2p,代码行数:30,代码来源:M2MFstAligner.cpp

示例7: abs

float
M2MFstAligner::maximization(bool lastiter)
{
    //Maximization. Simple count normalization.  Probably get an improvement
    // by using a more sophisticated regularization approach.
    map<LogArc::Label,LogWeight>::iterator it;
    float change = abs(total.Value() - prevTotal.Value());
    //cout << "Total: " << total << " Change: " << abs(total.Value()-prevTotal.Value()) << endl;
    prevTotal = total;

    //Normalize and iterate to the next model.  We apply it dynamically
    // during the expectation step.
    for (it = prev_alignment_model.begin();
            it != prev_alignment_model.end(); it++) {
        alignment_model[(*it).first] = Divide((*it).second, total);
        (*it).second = LogWeight::Zero();
    }

    for (int i = 0; i < fsas.size(); i++) {
        for (StateIterator<VectorFst<LogArc> > siter(fsas[i]);
                !siter.Done(); siter.Next()) {
            LogArc::StateId q = siter.Value();
            for (MutableArcIterator<VectorFst<LogArc> > aiter(&fsas[i], q); !aiter.Done(); aiter.Next()) {
                LogArc arc = aiter.Value();
                arc.weight = alignment_model[arc.ilabel];
                aiter.SetValue(arc);
            }
        }
    }

    total = LogWeight::Zero();
    return change;
}
开发者ID:ShahAlay,项目名称:sphinxtrain,代码行数:33,代码来源:M2MFstAligner.cpp

示例8: solve

void solve() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y), p[i].index = i, p[i].in = NULL;
	Alloc_memory(); sort(p, p + n);
	for (int i = 0; i < n; i++) Q[i] = p + i;
	edge *L, *R; Divide(0, n - 1, &L, &R);
	M = 0; Make_Graph(); Kruskal();
}
开发者ID:bywbilly,项目名称:Templates,代码行数:8,代码来源:Voronoi.cpp

示例9: 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

示例10: Term

void Term() {
  SignedFactor();
  while(Look == '*' || Look == '/') {
    EmitLn("push rax");
    switch(Look) {
    case '*' : Multiply();break;
    case '/' : Divide();break;
    }
  }
}
开发者ID:A-deLuna,项目名称:crenshaw-c-x86_64-compiler,代码行数:10,代码来源:main.c

示例11: main

int main()
{
    LinkList l,la,lb,lc;
    l=CreateList(7);
    la=CreateList2(0); lb=CreateList2(0); lc=CreateList2(0);
    Output(l);
    Divide(l,la,lb,lc);

    return 0;
}
开发者ID:mjyplusone,项目名称:CppPrimer,代码行数:10,代码来源:main.c

示例12: QuickMedium

void QuickMedium(T* &vector, int ini, int fin){
  if (fin-ini == 1){
    if (vector[ini]>vector[fin]) Swap(vector[ini], vector[fin]);
  }
  else if (fin-ini > 1){
    int division = Divide(vector, ini, fin);
    SlowMedium(vector, ini, division-1);
    SlowMedium(vector, division+1, fin);
  }
}
开发者ID:fgallegosalido,项目名称:Algoritmos-Ordenacion,代码行数:10,代码来源:mediumsort.cpp

示例13: Divide

// Divide this surface into two surfaces in
// S direction if bS is true,	u = (m_fS[0]+m_fS[1])/2
// T direction if bS is false,	u = (m_fT[0]+m_fT[1])/2
bool MH_SrfBezier::DivideHalf(bool bS, MH_SrfBezier& bezier1, MH_SrfBezier& bezier2) const
{
	float u;
	if(bS)
		u = (m_fS[0]+m_fS[1])/2.0f;
	else
		u = (m_fT[0]+m_fT[1])/2.0f;

	return Divide(bS, u, bezier1, bezier2);
}
开发者ID:KnowNo,项目名称:backup,代码行数:13,代码来源:MH_SrfBezier.cpp

示例14: Maze

Maze :: Maze()
{
  numRows = 21;
  numCols = 32;
  grid = new char*[numRows];
  for(int i = 0; i < numRows; i++)
    grid[i] = new char[numCols];
  /*
  strcpy (grid[0], "###############################");
  strcpy (grid[1], "#O#     #             #   #   #");
  strcpy (grid[2], "# # ### ##### # ##### ### # ###");
  strcpy (grid[3], "# # # #     # #     #   #     #");
  strcpy (grid[4], "# # # # # # ### ### ### # ### #");
  strcpy (grid[5], "# # #   # #   #   #   #     # #");
  strcpy (grid[6], "# # # ### ### ####### ##### # #");
  strcpy (grid[7], "#   # #     # #       #   # # #");
  strcpy (grid[8], "########### # # ######### # ###");
  strcpy (grid[9], "#           # # #   #         #");
  strcpy(grid[10], "# # # ####### # # # # # ##### #");
  strcpy(grid[11], "# # #   #   #   # # # # #     #");
  strcpy(grid[12], "### ### # # ##### ### # #######");
  strcpy(grid[13], "#   # # # #     #     # #   # #");
  strcpy(grid[14], "# # # # # # ############# # # #");
  strcpy(grid[15], "# # #   # #             # #   #");
  strcpy(grid[16], "# # ##### ##### ####### # #####");
  strcpy(grid[17], "# #     # #     #     #   #   #");
  strcpy(grid[18], "# ####### # ### # ### ##### # #");
  strcpy(grid[19], "#         #   #     #       #X#");
  strcpy(grid[20], "###############################");
  */
  for(int g = 0; g < 21; g++)
    {
      grid[g][0] = '#';
      grid[g][30] = '#';
    }
  for(int h = 0; h < 31; h++)
    {
      grid[0][h] = '#';
      grid[20][h] = '#';
    }
  for(int m = 1; m < 20; m++)
    for(int n = 1; n < 30; n++)
      grid[m][n] = ' ';

  srand(time(NULL));
  Divide(0, 20, 0, 30);

  endRow = 19;
  endCol = 29;
  currentRow = 1;
  currentCol = 1;
  
  grid[1][1] = 'O';
  grid[19][29] = 'X';
}
开发者ID:EricRobertBrewer,项目名称:SonomaState,代码行数:55,代码来源:Maze.cpp

示例15: macro6

void macro6(){

    auto sig_h=new TH1F("sig_h","Signal Histo",50,0,10);
    auto gaus_h1=new TH1F("gaus_h1","Gauss Histo 1",30,0,10);
    auto gaus_h2=new TH1F("gaus_h2","Gauss Histo 2",30,0,10);
    auto bkg_h=new TH1F("exp_h","Exponential Histo",50,0,10);

    // simulate the measurements
    TRandom3 rndgen;
    for (int imeas=0;imeas<4000;imeas++){
        bkg_h->Fill(rndgen.Exp(4));
        if (imeas%4==0) gaus_h1->Fill(rndgen.Gaus(5,2));
        if (imeas%4==0) gaus_h2->Fill(rndgen.Gaus(5,2));
        if (imeas%10==0)sig_h->Fill(rndgen.Gaus(5,.5));}

    // Format Histograms
    int i=0;
    for (auto hist : {sig_h,bkg_h,gaus_h1,gaus_h2})
        format_h(hist,1+i++);

    // Sum
    auto sum_h= new TH1F(*bkg_h);
    sum_h->Add(sig_h,1.);
    sum_h->SetTitle("Exponential + Gaussian;X variable;Y variable");
    format_h(sum_h,kBlue);

    auto c_sum= new TCanvas();
    sum_h->Draw("hist");
    bkg_h->Draw("SameHist");
    sig_h->Draw("SameHist");

    // Divide
    auto dividend=new TH1F(*gaus_h1);
    dividend->Divide(gaus_h2);

    // Graphical Maquillage
    dividend->SetTitle(";X axis;Gaus Histo 1 / Gaus Histo 2");
    format_h(dividend,kOrange);
    gaus_h1->SetTitle(";;Gaus Histo 1 and Gaus Histo 2");
    gStyle->SetOptStat(0);

    TCanvas* c_divide= new TCanvas();
    c_divide->Divide(1,2,0,0);
    c_divide->cd(1);
    c_divide->GetPad(1)->SetRightMargin(.01);
    gaus_h1->DrawNormalized("Hist");
    gaus_h2->DrawNormalized("HistSame");

    c_divide->cd(2);
    dividend->GetYaxis()->SetRangeUser(0,2.49);
    c_divide->GetPad(2)->SetGridy();
    c_divide->GetPad(2)->SetRightMargin(.01);
    dividend->Draw();
}
开发者ID:A2-Collaboration,项目名称:root,代码行数:54,代码来源:macro6.C


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