本文整理汇总了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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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();
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例10: Term
void Term() {
SignedFactor();
while(Look == '*' || Look == '/') {
EmitLn("push rax");
switch(Look) {
case '*' : Multiply();break;
case '/' : Divide();break;
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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';
}
示例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();
}