void Parser::Expp() { switch(look.kind) { case LT: case TIMES: case PLUS: case OR: case AND: case GT: case EQ: case MINUS: case DIV: Op();Exp();Expp();return; case LBRACK: Match(LBRACK);Exp();Match(RBRACK);Expp();return; case DOT: Match(DOT); switch(look.kind) { case LENGTH:Match(LENGTH);Expp();return; case ID: Id();Match(LPAREN);ExpList();Match(RPAREN);Expp(); default: return; } case RPAREN: case SEMICOLON: return; } }
int ConstExpression::P() { Operator *op; if(op=GetOperator(Next()->type_id(),1)) // unary { Consume(); int q = op->prec; int t = Exp(q); return MakeNode(op,t,0); } else if(Next()->type_id()==TKN_L_PAREN) { Consume(); int t = Exp(0); Expect(TKN_R_PAREN); return t; } else if(Next()->type_id()==TKN_NUMBER) { int t = atoi(Next()->get_text().c_str()); Consume(); return t; } else exit(0); }
void EnvelopeGen::OnProcess(int voiceID, Synth* synth) { EnvelopeGenVoiceData &data = mVoiceData[voiceID]; Frame<SampleType> &output = mOutputs[0].frame; if (data.postRelease) { // release envelope for (size_t i = 0; i < synth->GetFrameSize(); i++) { output[i] = data.releaseVolume * Exp(-data.time * mReleaseInv); data.time += synth->GetSampleRateInv(); } } else { for (size_t i = 0; i < synth->GetFrameSize(); i++) { if (data.time < mAttack) // attack envelope output[i] = 0.5 - 0.5 * Cos(data.time * mAttackInv * M_PI); else if (data.time > 0.0) output[i] = mSustain + (1.0f - mSustain) * Exp(-(data.time - mAttack) * mDecayInv); else output[i] = 0.0; data.time += synth->GetSampleRateInv(); } data.lastValue = output[synth->GetFrameSize() - 1]; } }
Fdm2dBlackScholesOp::Fdm2dBlackScholesOp( const boost::shared_ptr<FdmMesher>& mesher, const boost::shared_ptr<GeneralizedBlackScholesProcess>& p1, const boost::shared_ptr<GeneralizedBlackScholesProcess>& p2, Real correlation, Time maturity, bool localVol, Real illegalLocalVolOverwrite) : mesher_(mesher), p1_(p1), p2_(p2), localVol1_((localVol) ? p1->localVolatility().currentLink() : boost::shared_ptr<LocalVolTermStructure>()), localVol2_((localVol) ? p2->localVolatility().currentLink() : boost::shared_ptr<LocalVolTermStructure>()), x_((localVol) ? Array(Exp(mesher->locations(0))) : Array()), y_((localVol) ? Array(Exp(mesher->locations(1))) : Array()), opX_(mesher, p1, p1->x0(), localVol, illegalLocalVolOverwrite, 0), opY_(mesher, p2, p2->x0(), localVol, illegalLocalVolOverwrite, 1), corrMapT_(0, 1, mesher), corrMapTemplate_(SecondOrderMixedDerivativeOp(0, 1, mesher) .mult(Array(mesher->layout()->size(), correlation))), illegalLocalVolOverwrite_(illegalLocalVolOverwrite) { }
Spectrum operator()(float d2) const { Spectrum dpos = Sqrt(Spectrum(d2) + zpos * zpos); Spectrum dneg = Sqrt(Spectrum(d2) + zneg * zneg); Spectrum Rd = (1.f / (4.f * M_PI)) * ((zpos * (dpos * sigma_tr + Spectrum(1.f)) * Exp(-sigma_tr * dpos)) / (dpos * dpos * dpos) - (zneg * (dneg * sigma_tr + Spectrum(1.f)) * Exp(-sigma_tr * dneg)) / (dneg * dneg * dneg)); return Rd.Clamp(); }
static void Exact(PetscReal t, PetscReal omega,PetscReal xi,PetscReal u0,PetscReal v0, PetscReal *ut,PetscReal *vt) { #define Sin PetscSinReal #define Cos PetscCosReal #define Exp PetscExpReal #define Sqrt PetscSqrtReal PetscReal u,v; if (xi < 1) { PetscReal a = xi*omega; PetscReal w = Sqrt(1-xi*xi)*omega; PetscReal C1 = (v0 + a*u0)/w; PetscReal C2 = u0; u = Exp(-a*t) * (C1*Sin(w*t) + C2*Cos(w*t)); v = (- a * Exp(-a*t) * (C1*Sin(w*t) + C2*Cos(w*t)) + w * Exp(-a*t) * (C1*Cos(w*t) - C2*Sin(w*t))); } else if (xi > 1) { PetscReal w = Sqrt(xi*xi-1)*omega; PetscReal C1 = (w*u0 + xi*u0 + v0)/(2*w); PetscReal C2 = (w*u0 - xi*u0 - v0)/(2*w); u = C1*Exp((-xi+w)*t) + C2*Exp((-xi-w)*t); v = C1*(-xi+w)*Exp((-xi+w)*t) + C2*(-xi-w)*Exp((-xi-w)*t); } else { PetscReal a = xi*omega; PetscReal C1 = v0 + a*u0; PetscReal C2 = u0; u = (C1*t + C2) * Exp(-a*t); v = (C1 - a*(C1*t + C2)) * Exp(-a*t); } if (ut) *ut = u; if (vt) *vt = v; }
int main () { int k,p; float s; for ( k=0; k<100; k++){ p= (2*(Exp (-1,k))*(Exp (3, 0.5-k)))/((2*k)+1); s=s+p; } printf ( " El valor de pi es:%.5f",s); return 0; }
void GJointRevolute::update_short() { if ( bReversed ) { T = SE3(Exp(-axis*coordinate.q), Vec3(0,0,0)); inv_T = SE3(~T.GetRotation()); S[0] = -axis[0]; S[1] = -axis[1]; S[2] = -axis[2]; } else { T = SE3(Exp(axis*coordinate.q), Vec3(0,0,0)); inv_T = SE3(~T.GetRotation()); S[0] = axis[0]; S[1] = axis[1]; S[2] = axis[2]; } }
void Pdb::SetTree(const String& exp) { SaveTree(); tree.Clear(); NamedVal nv; try { CParser p(exp); nv.val = Exp(p); } catch(CParser::Error) { return; } nv.name = exp; String n = exp; if(nv.val.type >= 0) n = GetType(nv.val.type).name; tree.SetRoot(Null, RawToValue(nv), n + '=' + Visualise(nv.val).GetString()); if(nv.val.type >= 0) { String w = treetype.Get(n, Null); LOG("SetTree " << n << ' ' << w); tree.Open(0); CParser p(w); try { Point sc; sc.x = p.ReadInt(); sc.y = p.ReadInt(); int cursor = p.ReadInt(); ExpandTreeType(0, p); tree.ScrollTo(sc); if(cursor >= 0) tree.SetCursor(cursor); } catch(CParser::Error) {} } }
void Pdb::Explorer() { VectorMap<String, Value> prev = DataMap(explorer); explorer.Clear(); try { String x = ~expexp; if(!IsNull(x)) { CParser p(x); Val v = Exp(p); Vis(explorer, "=", prev, Visualise(v)); if(v.type >= 0 && v.ref == 0 && !v.rvalue) Explore(v, prev); if(v.ref > 0 && GetRVal(v).address) for(int i = 0; i < 20; i++) Vis(explorer, Format("[%d]", i), prev, Visualise(DeRef(Compute(v, RValue(i), '+')))); } } catch(CParser::Error e) { Visual v; v.Cat(e, LtRed); explorer.Add("", RawPickToValue(v)); } exback.Enable(exprev.GetCount()); exfw.Enable(exnext.GetCount()); }
inline void NewtonStep ( const DistMatrix<F>& X, DistMatrix<F>& XNew, Scaling scaling=FROB_NORM ) { #ifndef RELEASE CallStackEntry entry("sign::NewtonStep"); #endif typedef BASE(F) Real; // Calculate mu while forming B := inv(X) Real mu; DistMatrix<Int,VC,STAR> p( X.Grid() ); XNew = X; LU( XNew, p ); if( scaling == DETERMINANT ) { SafeProduct<F> det = determinant::AfterLUPartialPiv( XNew, p ); mu = Real(1)/Exp(det.kappa); } inverse::AfterLUPartialPiv( XNew, p ); if( scaling == FROB_NORM ) mu = Sqrt( FrobeniusNorm(XNew)/FrobeniusNorm(X) ); else if( scaling == NONE ) mu = 1; else LogicError("Scaling case not handled"); // Overwrite XNew with the new iterate const Real halfMu = mu/Real(2); const Real halfMuInv = Real(1)/(2*mu); Scale( halfMuInv, XNew ); Axpy( halfMu, X, XNew ); }
/** * Return the path name of the UObject represented by the specified export. * (can be used with StaticFindObject) * * @param ExportIndex index into the ExportMap for the resource to get the name for * @param FakeRoot Optional name to replace use as the root package of this object instead of the linker * @param bResolveForcedExports if true, the package name part of the return value will be the export's original package, * not the name of the package it's currently contained within. * * @return the path name of the UObject represented by the resource at ExportIndex */ FString FLinker::GetExportPathName(int32 ExportIndex, const TCHAR* FakeRoot,bool bResolveForcedExports/*=false*/) { FString Result; bool bForcedExport = false; for ( FPackageIndex LinkerIndex = FPackageIndex::FromExport(ExportIndex); !LinkerIndex.IsNull(); LinkerIndex = Exp(LinkerIndex).OuterIndex ) { const FObjectExport Export = Exp(LinkerIndex); // don't append a dot in the first iteration if ( Result.Len() > 0 ) { // if this export is not a UPackage but this export's Outer is a UPackage, we need to use subobject notation if ((Export.OuterIndex.IsNull() || GetExportClassName(Export.OuterIndex) == NAME_Package) && GetExportClassName(LinkerIndex) != NAME_Package) { Result = FString(SUBOBJECT_DELIMITER) + Result; } else { Result = FString(TEXT(".")) + Result; } } Result = Export.ObjectName.ToString() + Result; bForcedExport = bForcedExport || Export.bForcedExport; } if ( bForcedExport && FakeRoot == NULL && bResolveForcedExports ) { // Result already contains the correct path name for this export return Result; } return (FakeRoot ? FakeRoot : LinkerRoot->GetPathName()) + TEXT(".") + Result; }
BOOL COXTreeItem::Expand(UINT nCode,COXTreeCtrl *pCtrl) { ASSERT(pCtrl!=NULL); BOOL bWasVisible=IsVisible(); switch(nCode) { case TVE_TOGGLE: m_bExpand = !m_bExpand; break; case TVE_COLLAPSE: if(!m_bExpand) { TRACE(_T("COXTreeItem::Expand: the item is already in collapsed state!\n")); return TRUE; } m_bExpand = FALSE; break; case TVE_EXPAND: if(m_bExpand) { TRACE(_T("COXTreeItem::Expand: the item is already in expanded state!\n")); return TRUE; } m_bExpand = TRUE; break; case TVE_COLLAPSERESET: pCtrl->DeleteChildrenItems(this); m_bExpand=FALSE; m_bExpandedOnce=FALSE; m_tvi.cChildren=0; return TRUE; default: TRACE(_T("COXTreeItem::Expand: unexpected case found!\n")); return FALSE; } if(m_bExpand) m_bExpandedOnce=TRUE; if(!bWasVisible && !m_bExpand) return TRUE; if(!IsVisible() && m_bExpand) { COXTreeItem* xtiParent=pxParent; ASSERT(xtiParent!=NULL && xtiParent!=&pCtrl->m_xtiRoot); xtiParent->Expand(TVE_EXPAND,pCtrl); } else Exp(pCtrl); return TRUE; }
void CNE6SSM_high_scale_constraint<Two_scale>::update_scale() { assert(model && "CNE6SSM_high_scale_constraint<Two_scale>::" "update_scale(): model pointer is zero."); const double currentScale = model->get_scale(); const CNE6SSM_soft_parameters beta_functions(model->calc_beta()); const auto g1 = MODELPARAMETER(g1); const auto g2 = MODELPARAMETER(g2); const auto beta_g1 = BETAPARAMETER(g1); const auto beta_g2 = BETAPARAMETER(g2); scale = currentScale*Exp((-g1 + g2)/(BETA(g1) - BETA(g2))); if (errno == ERANGE) { #ifdef ENABLE_VERBOSE ERROR("CNE6SSM_high_scale_constraint<Two_scale>: Overflow error" " during calculation of high scale: " << strerror(errno) << '\n' << " current scale = " << currentScale << '\n' << " new scale = " << scale << '\n' << " resetting scale to " << get_initial_scale_guess()); #endif scale = get_initial_scale_guess(); errno = 0; } }
inline void MakeDiscreteFourier( DistMatrix<Complex<R>,U,V>& A ) { #ifndef RELEASE CallStackEntry entry("MakeDiscreteFourier"); #endif typedef Complex<R> F; const int m = A.Height(); const int n = A.Width(); if( m != n ) throw std::logic_error("Cannot make a non-square DFT matrix"); const R pi = 4*Atan( R(1) ); const F nSqrt = Sqrt( R(n) ); const int localHeight = A.LocalHeight(); const int localWidth = A.LocalWidth(); const int colShift = A.ColShift(); const int rowShift = A.RowShift(); const int colStride = A.ColStride(); const int rowStride = A.RowStride(); for( int jLocal=0; jLocal<localWidth; ++jLocal ) { const int j = rowShift + jLocal*rowStride; for( int iLocal=0; iLocal<localHeight; ++iLocal ) { const int i = colShift + iLocal*colStride; A.SetLocal( iLocal, jLocal, Exp(-2*pi*i*j/n)/nSqrt ); const R theta = -2*pi*i*j/n; const Complex<R> alpha( Cos(theta), Sin(theta) ); A.SetLocal( iLocal, jLocal, alpha/nSqrt ); } } }
void Pdb::MemMenu(ArrayCtrl& array, Bar& bar, const String& exp) { if(bar.IsScanKeys()) return; CParser p(exp); try { Val v = Exp(p); bool sep = true; if(v.ref > 0) { if(sep) bar.Separator(); sep = false; bar.Add("Memory at " + exp, THISBACK1(MemoryGoto, exp)); } else if(v.rvalue) { if(sep) bar.Separator(); sep = false; bar.Add("Memory at 0x" + FormatIntHex((dword)GetInt(v)), THISBACK1(MemoryGoto, "&" + exp)); } if(!v.rvalue) { if(sep) bar.Separator(); sep = false; bar.Add("Memory at &&" + exp, THISBACK1(MemoryGoto, "&" + exp)); } } catch(CParser::Error e) { } }
void calT() { double a; e=6.11*Exp(); a=0.5555*(e-10.0); t=h-a; }
void calH() { double a; e=6.11*Exp(); a=0.5555*(e-10.0); h=t+a; }
static int quat_exp(lua_State* L) { Quatf* x = check_quat(L, 1); new_quat(L, result); *result = Exp(*x); return 1; }
void NewtonStep ( const DistMatrix<Field>& X, DistMatrix<Field>& XNew, SignScaling scaling=SIGN_SCALE_FROB ) { EL_DEBUG_CSE typedef Base<Field> Real; // Calculate mu while forming B := inv(X) Real mu=1; DistPermutation P( X.Grid() ); XNew = X; LU( XNew, P ); if( scaling == SIGN_SCALE_DET ) { SafeProduct<Field> det = det::AfterLUPartialPiv( XNew, P ); mu = Real(1)/Exp(det.kappa); } inverse::AfterLUPartialPiv( XNew, P ); if( scaling == SIGN_SCALE_FROB ) mu = Sqrt( FrobeniusNorm(XNew)/FrobeniusNorm(X) ); // Overwrite XNew with the new iterate const Real halfMu = mu/Real(2); const Real halfMuInv = Real(1)/(2*mu); XNew *= halfMuInv; Axpy( halfMu, X, XNew ); }
void Parser::ExpList() { if(look.kind == RPAREN) return; Exp(); ExpRests(); }
inline hvl_float CalcB1pB2(const HVL_Context *ctx, const hvl_float &a3, const hvl_float &sqrtz) { const hvl_float b1 = ctx->HVL_ONE / (Exp(a3) - ctx->HVL_ONE); const hvl_float b2 = ctx->HVL_HALF * (ctx->HVL_ONE + Erf(sqrtz)); return b1 + b2; }
struct syntax_node * factor(){ struct syntax_node * t; t = (struct syntax_node*)malloc(sizeof(struct syntax_node)); chushihua_t(t); if(strcmp(current_token->value, "(") == 0) { t->child[0] = zuokuohao(); t->child[1] = Exp(); t->child[2] = youkuohao(); } else if(strcmp(current_token->kind, "INTC") == 0) { t->child[0] = intc(); } else { t->child[0] = variable(); } strcpy(t->kind_name, "Factor"); return t; }
int ConstExpression::expression_eval(quex::Token *tokenInput) { m_InputToken = tokenInput; int t = Exp(0); Expect(TKN_TERMINATION); std::cout<<t<<std::endl; return EXIT_SUCCESS; }
void Write_Stmt() { match("write"); Exp(); printf("Write Statment is found\n"); pFileOut=fopen(OutputFile,"a"); fputs("Write Statment is found\n", pFileOut); }
static void _hoc_Exp(void) { double _r; double* _p; Datum* _ppvar; Datum* _thread; _NrnThread* _nt; if (_extcall_prop) {_p = _extcall_prop->param; _ppvar = _extcall_prop->dparam;}else{ _p = (double*)0; _ppvar = (Datum*)0; } _thread = _extcall_thread; _nt = nrn_threads; _r = Exp ( _p, _ppvar, _thread, _nt, *getarg(1) ); hoc_retpushx(_r); }
void Assign_Stmt() { match("identifier"); match(":="); Exp(); printf("Assignment is found\n"); pFileOut=fopen(OutputFile,"a"); fputs("Assignment is found\n", pFileOut); }
int Exp (int n, int m){ int p; if (m== 1) p= n; if (m== 2) p= m*m; if ((n!=1)&&(n!=2)) p= (Exp (n, m-1))*n; return p; }
struct syntax_node * rel_exp(){ struct syntax_node * t; t = (struct syntax_node*)malloc(sizeof(struct syntax_node)); chushihua_t(t); t->child[0] = Exp(); t->child[1] = other_rel_e(); strcpy(t->kind_name, "RelExp"); return t; }
void Repeat_Stmt() { match("repeat"); Stmt_sequence(); match("until"); Exp(); printf("Repeat is found\n"); pFileOut=fopen(OutputFile,"a"); fputs("Repeat is found\n", pFileOut); }