int main() { // printf("hello, world"); char result[BUFFER_SIZE]; char remainder[BUFFER_SIZE]; // please make sure the bit length is enough before calculate // especially when you do a large power operation // you can change it by define: BIG_INT_BIT_LEN // the default bit length for BigInt is 1024 // routine test puts(Add("2010", "4", result)); puts(Sub("0", "2014", result)); puts(Mul("2", "43", result)); puts(Div("86", "10", result, remainder)); puts(remainder); puts(Mod("-86", "10", result)); puts(PowMod("7", "80", "86", result)); // BigInt test puts(Sub("233333333333333333333333333333333333333333333333", "33", result)); puts(Mul("2333333333333333333333333333333", "2333333333333333333", result)); puts(Div("2333333333333333333333333333333", "2333333333333333332", result, remainder)); puts(remainder); puts(Pow("8", "86", result)); return 0; }
static inline void SolveEqs(Cut *cut, count ncut, creal *delta, creal diff) { real last = 0; real r = 1; Cut *c; for( c = cut; ; ++c ) { ccount dim = Dim(c->i); c->row = r -= Div(diff, (delta[Lower(dim)] + delta[Upper(dim)])*c->df); if( --ncut == 0 ) break; last += r*c->lhs; } last = Div(c->lhs - last, r); for( ; c >= cut; last += (--c)->lhs ) { creal delmin = -(c->delta = delta[c->i]); creal delmax = FRACT*(delmin + c->save); c->sol = Div(last, c->df); if( c->sol > delmax ) c->sol = .75*delmax; if( c->sol < delmin ) c->sol = .75*delmin; } }
virtual void layout() { Point size=getSize(); Coord dx=Div(4,21)*size.x; Coord dy=Div(4,21)*size.y; Coord x0=dx/4; Coord y0=dy/4; Coord delta_x=dx+x0; Coord delta_y=dy+y0; if( dx>0 && dy>0 ) { for(int i=0; i<4 ;i++) for(int j=0; j<4 ;j++) { pane[i][j]=Pane(x0+i*delta_x,y0+j*delta_y,dx,dy); } } else { for(int i=0; i<4 ;i++) for(int j=0; j<4 ;j++) { pane[i][j]=Empty; } } }
void Work(void) { int64 P[5] = {1, 2}; while (!Zero(a) && !Zero(b)) { bool Odda = a[1] & 1, Oddb = b[1] & 1; if (Odda && Oddb) { Decreas(a, b); }else if (!Odda && !Oddb) { Div(a); Div(b); Mult(delta, P); }else if (Odda && !Oddb) { Div(b); }else if (!Odda && Oddb) { Div(a); } } if (Zero(a)) { Mult(b, delta); Print(b); } else { Mult(a, delta); Print(a); } }
void main() { try{ cout <<"7.3/2.0 = " <<Div(7.3, 2.0) <<endl; cout <<"7.3/0.0 = " <<Div(7.3, 0.0) <<endl; cout <<"7.3/1.0 = " <<Div(7.3, 1.0) <<endl; } catch(double) { cout <<"发生除数为零的异常\n"; } cout <<"程序执行成功\n"; }
status_t _GlBinaryOp2d::Process( const GlPlanes* src, GlPlanes& dest, GlProcessStatus* status) { if (dest.size < 1) return B_OK; GlAlgo2d* lh = Algo2dAt(_LH_INDEX); GlAlgo2d* rh = Algo2dAt(_RH_INDEX); if (lh && rh) { GlPlanes* c = dest.Clone(); if (c && c->size == dest.size) { lh->Process(src, dest, status); rh->Process(src, *c, status); if (mOp == GL_ADD_BINARY_SRF_KEY) Add(dest, *c); else if (mOp == GL_SUB_BINARY_SRF_KEY) Sub(dest, *c); else if (mOp == GL_MULT_BINARY_SRF_KEY) Mult(dest, *c); else if (mOp == GL_DIV_BINARY_SRF_KEY) Div(dest, *c); else if (mOp == GL_MIN_BINARY_SRF_KEY) Min(dest, *c); else if (mOp == GL_MAX_BINARY_SRF_KEY) Max(dest, *c); else ArpASSERT(false); } delete c; } else if (lh) { lh->Process(src, dest, status); } else if (rh) { rh->Process(src, dest, status); } return B_OK; }
BigData BigData::operator/(const BigData& bigdata) { if (bigdata._strData[1] == '0') { cout << "除数为 0 " << endl; assert(0); } if (_strData[1] == 0) return INT64(0); if ((IsINT64OverFlow()) && bigdata.IsINT64OverFlow()) { return _value / bigdata._value; } if (_strData.size() < bigdata._strData.size()) { return INT64(0); } else if (_strData.size() == bigdata._strData.size()) { if (strcmp(_strData.c_str() + 1, bigdata._strData.c_str() + 1) < 0) return INT64(0); if (strcmp(_strData.c_str() + 1, bigdata._strData.c_str() + 1) == 0) { if (_strData[0] == bigdata._strData[0]) return INT64(1); else return INT64(-1); } } return BigData(Div(_strData, bigdata._strData).c_str()); }
char *Ricerca_e_deriva(char *funzione_1, char *funzione_2, char *operatore, char *output) { output = (char *)malloc(sizeof(char)*10000); if ( strcmp(operatore,"x") == 0 || ( strcmp(operatore,"plus") != 0 && strcmp(operatore,"mul") != 0 && strcmp(operatore,"sot") != 0 && strcmp(operatore,"pow") != 0 )) output = D_Fondamentali(operatore); // Se il primo operando è una x oppure non è nessuna delle funzioni previste allora chiama D_Fondamentali if(strcmp(operatore,"pow") == 0) // Potenza output = Pow(funzione_1,funzione_2, output); if(strcmp(operatore,"mul") == 0) // Prodotto output = Mul(funzione_1 ,funzione_2, output); if(strcmp(operatore,"div") == 0) // Rapporto output = Div(funzione_1 ,funzione_2, output); if(strcmp(operatore,"plus") == 0) // Somma output = Sum(funzione_1,funzione_2, output); if(strcmp(operatore,"sot") == 0) // Differenza output = Sot(funzione_1,funzione_2, output); if(strcmp(operatore,"sin") == 0) // Seno output = Sin(funzione_1, "", output); if(strcmp(operatore,"cos") == 0) // Coseno output = Cos(funzione_1, "", output); return output; // Ritorno la funzione già derivata }
void Combine( int Positions[], FILE *InputFiles[], int NumberInputs ) { int OddNibble ; BOOLEAN Odd ; int i ; int j ; G13 C[15] ; G13 c ; G13 Y[15] ; BOOLEAN FillNibbles( G13 *Nibbles, FILE *InputFiles[], int NumberInputs ); setmode( fileno( stdout ), O_BINARY ) ; /* Compute the coefficients by which the nibbles from the * various input files can be combined to produce the output * file. * If X(i) is the "position" of the ith input file, and * Y(i) is the value of a particular nibble in the ith file, * we will find coefficients C(i) such that * * p = C(1) * Y(1) + C(2) * Y(2) + ... * * where p is the appropriate nibble for the output file. * * The formula for the Cs is: * * C(i) = product of ( X(j) / ( X(i) - X(j) ) ) for all j != i . * * */ for ( i = 0; i < NumberInputs; i++ ) { c = 1 ; for ( j = 0; j < NumberInputs; j++ ) if ( j != i ) c = Mult( c, Div( Positions[j], Positions[i] ^ Positions[j] ) ) ; C[i] = c ; } /* * Now, process the input files: */ Odd = TRUE ; while ( FillNibbles( Y, InputFiles, NumberInputs ) ) { c = 0 ; for ( i = 0; i < NumberInputs; i++ ) c ^= Mult( C[i], Y[i] ) ; if ( Odd ) OddNibble = c ; else putchar( ( OddNibble << 4 ) | c ) ; Odd = !Odd ; } }
HugeNumber operator % ( HugeNumber &u, HugeNumber &v) // Ostatok ot delenija { HugeNumber a,r; Div(u,v,a,r); return r; };
BigData BigData::operator / (const BigData& bigdata) { if (bigdata._pData == "+0") { assert(false); std::cout << "FileName :" <<__FILE__ << "Line :" << __LINE__ << std::endl; } if (_pData == "+0") { return BigData((INT64)0); } int LSize = _pData.size(); int RSize = bigdata._pData.size(); if (LSize < RSize || (LSize == RSize && strcmp(_pData.c_str() + 1, bigdata._pData.c_str() + 1) < 0)) { return BigData((INT64)0); } if (strcmp(_pData.c_str() + 1, bigdata._pData.c_str() + 1) == 0) { if (_pData[0] == bigdata._pData[0]) { return BigData((INT64)1); } else { return BigData((INT64)-1); } } if (bigdata._pData == "+1") { return *this; } if (bigdata._pData == "-1") { std::string strRet(_pData); if (strRet[0] == '+') { strRet[0] = '-'; _value = 0 - _value; } else { strRet[0] = '+'; _value = 0 - _value; } return BigData((char *)strRet.c_str()); } //LSize > RSize return BigData((char *)Div(_pData, bigdata._pData).c_str()); }
// Preset Load bool SweepSettings::Load(QSettings &s) { mode = (OperationalMode)(s.value("Mode", (int)Mode()).toInt()); start = s.value("Sweep/Start", Start().Val()).toDouble(); stop = s.value("Sweep/Stop", Stop().Val()).toDouble(); center = s.value("Sweep/Center", Center().Val()).toDouble(); span = s.value("Sweep/Span", Span().Val()).toDouble(); step = s.value("Sweep/Step", Step().Val()).toDouble(); rbw = s.value("Sweep/RBW", RBW().Val()).toDouble(); vbw = s.value("Sweep/VBW", VBW().Val()).toDouble(); auto_rbw = s.value("Sweep/AutoRBW", AutoRBW()).toBool(); auto_vbw = s.value("Sweep/AutoVBW", AutoVBW()).toBool(); native_rbw = s.value("Sweep/NativeRBW", NativeRBW()).toBool(); refLevel.Load(s, "Sweep/RefLevel"); div = s.value("Sweep/Division", Div()).toDouble(); attenuation = s.value("Sweep/Attenuation", Atten()).toInt(); gain = s.value("Sweep/Gain", Gain()).toInt(); preamp = s.value("Sweep/Preamp", Preamp()).toInt(); sweepTime = s.value("Sweep/SweepTime", SweepTime().Val()).toDouble(); processingUnits = s.value("Sweep/ProcessingUnits", ProcessingUnits()).toInt(); detector = s.value("Sweep/Detector", Detector()).toInt(); rejection = s.value("Sweep/Rejection", Rejection()).toBool(); tgSweepSize = s.value("Sweep/TgSweepSize", tgSweepSize).toInt(); tgHighRangeSweep = s.value("Sweep/TgHighRangeSweep", tgHighRangeSweep).toBool(); tgPassiveDevice = s.value("Sweep/TgPassiveDevice", tgPassiveDevice).toBool(); UpdateProgram(); return true; }
void DivArm () { uint32_t tmp = R(0); R(0) = R(1); R(1) = tmp; Div(); }
int physics_run(real t) { //output.write("Running %e\n", t); // Run communications comms.run(); // Density F_N = -V_dot_Grad(V, N) - N*Div(V); //output.write("N "); // Velocity F_V = -V_dot_Grad(V, V) - Grad(P)/N + g; if(sub_initial) { F_V += Grad(P0)/N0 - g; } //output.write("V "); if(include_viscosity) { // Add viscosity F_V.y += nu*Laplacian(V.y); F_V.z += nu*Laplacian(V.z); //output.write("nu "); } // Pressure F_P = -V_dot_Grad(V, P) - gamma_ratio*P*Div(V); //output.write("P\n"); // Set boundary conditions apply_boundary(F_N, "density"); apply_boundary(F_P, "pressure"); F_V.to_contravariant(); apply_boundary(F_V, "v"); //output.write("finished\n"); return 0; }
void CoordEditWindow::layout() { Point size=getSize(); spin.setPlace(Pane(Null,size.x,size.y/2)); pos.x=size.x/2; pos.y=Div(3,4)*size.y; }
int physics_run(real t) { // Run communications comms.run(); msg_stack.push("F_rho"); F_rho = -V_dot_Grad(v, rho) - rho*Div(v); msg_stack.pop(); msg_stack.push("F_p"); F_p = -V_dot_Grad(v, p) - gamma*p*Div(v); msg_stack.pop(); msg_stack.push("F_v"); F_v = -V_dot_Grad(v, v) + ((Curl(B)^B) - Grad(p))/rho; if(include_viscos) { F_v.x += viscos * Laplacian(F_v.x); F_v.y += viscos * Laplacian(F_v.y); F_v.z += viscos * Laplacian(F_v.z); } msg_stack.pop(); msg_stack.push("F_B"); F_B = Curl(v^B); // boundary conditions apply_boundary(F_rho, "density"); apply_boundary(F_p, "pressure"); F_v.to_covariant(); apply_boundary(F_v, "v"); F_B.to_contravariant(); apply_boundary(F_B, "B"); msg_stack.pop(); msg_stack.push("DivB"); divB = Div(B); // Just for diagnostic bndry_inner_zero(divB); bndry_sol_zero(divB); return 0; }
/////////////////////////// // Divide everything by nNUm sMoney sMoney::operator /(int nNum) { sMoney Div(*this); Div.Copper/=nNum; Div.Gold/=nNum; Div.Silver/=nNum; Div.Plat/=nNum; Div.ReCalcBase(); return Div; }
tmp<GeometricField<Type, fvPatchField, volMesh> > div ( const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >& tssf ) { tmp<GeometricField<Type, fvPatchField, volMesh> > Div(fvc::div(tssf())); tssf.clear(); return Div; }
int SOPAngle::__div(lua_State *L) { SOPAngle *ang = Div(luaL_checknumber(L, 1)); if(ang) { Lunar<SOPAngle>::push(L, ang, true); return 1; } lua_pushnil(L); return 1; }
tmp<GeometricField<Type, faPatchField, areaMesh> > div ( const tmp<GeometricField<Type, faePatchField, edgeMesh> >& tssf ) { tmp<GeometricField<Type, faPatchField, areaMesh> > Div(fac::div(tssf())); tssf.clear(); return Div; }
tmp<fvMatrix<Type> > div ( const tmp<surfaceScalarField>& tflux, const GeometricField<Type, fvPatchField, volMesh>& vf ) { tmp<fvMatrix<Type> > Div(fvm::div(tflux(), vf)); tflux.clear(); return Div; }
int _tmain(int argc, _TCHAR* argv[]) { int result1 = Add( 10 , 20 ); printf("%d \n",result1); int result2 = Minus( 10 , 20 ); printf("%d \n",result2); int result3 = Mul( 10 , 20 ); printf("%d \n",result3); int result4 = Div( 10 , 20 ); printf("%d \n",result4); return 0; }
TString MillePedeTrees::RPos(const TString &tree) const { const TString r(Sqrt(RPos2(tree))); if (fUseSignedR) { const TString y(tree + Pos(2)); return r + Mal() += Parenth(Fun("TMath::Abs", y) += Div() += y); } else { return r; } }
BigData BigData::operator/(const BigData& bigData) { if (bigData.m_llValue == 0) { assert("³ýÊý²»ÄÜΪ0"); return BigData(INT64(0)); } if (!IsINT64Overflow() && bigData.IsINT64Overflow()) { return BigData(m_llValue / bigData.m_llValue); } return BigData(Div(m_strData, bigData.m_strData).c_str()); }
TString MillePedeTrees::DelRphi(const TString &tree1, const TString &tree2) const { // distance vector in rphi/xy plane times unit vector e_phi = (-y/r, x/r) // tree2 gives reference for e_phi const TString deltaX = Parenth(tree1 + XPos() += (Min() += tree2) += XPos()); const TString deltaY = Parenth(tree1 + YPos() += (Min() += tree2) += YPos()); // (delta_x * (-y) + delta_y * x) / r // protect against possible sign of RPos: return Parenth(Parenth(deltaX + Mal() += ("-" + tree2) += YPos() += Plu() += deltaY + Mal() += tree2 + XPos() ) += Div() += Sqrt(RPos2(tree2)) //RPos(tree2) ); }
tmp<GeometricField<Type, fvPatchField, volMesh> > div ( const surfaceScalarField& flux, const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf ) { tmp<GeometricField<Type, fvPatchField, volMesh> > Div ( fvc::div(flux, tvf()) ); tvf.clear(); return Div; }
tmp<GeometricField<Type, faPatchField, areaMesh> > div ( const edgeScalarField& flux, const tmp<GeometricField<Type, faPatchField, areaMesh> >& tvf ) { tmp<GeometricField<Type, faPatchField, areaMesh> > Div ( fac::div(flux, tvf()) ); tvf.clear(); return Div; }
tmp<GeometricField<Type, faPatchField, areaMesh> > div ( const tmp<edgeScalarField>& tflux, const GeometricField<Type, faPatchField, areaMesh>& vf ) { tmp<GeometricField<Type, faPatchField, areaMesh> > Div ( fac::div(tflux(), vf) ); tflux.clear(); return Div; }
Expression *DivExp::optimize(int result) { Expression *e; //printf("DivExp::optimize(%s)\n", toChars()); e1 = e1->optimize(result); e2 = e2->optimize(result); if (e1->isConst() == 1 && e2->isConst() == 1) { e = Div(type, e1, e2); } else e = this; return e; }
tmp<GeometricField<Type, fvPatchField, volMesh> > div ( const tmp<surfaceScalarField>& tflux, const GeometricField<Type, fvPatchField, volMesh>& vf, const word& name ) { tmp<GeometricField<Type, fvPatchField, volMesh> > Div ( fvc::div(tflux(), vf, name) ); tflux.clear(); return Div; }