//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void gosFX::CurveKey::ComputeRange( Stuff::Scalar *low, Stuff::Scalar *hi, Stuff::Scalar dt ) { Check_Object(this); Check_Pointer(low); Check_Pointer(hi); // //------------------------------------------------------------------------ // We know that we will have to test the function at the beginning and end // of the segment, so go ahead and do that now //------------------------------------------------------------------------ // *hi = *low = m_value; if (dt < Stuff::SMALL) return; Stuff::Scalar t = ComputeValue(dt); if (t>*hi) *hi = t; else if (t<*low) *low = t; }
T SrBuffer<T>::ComputeValueAtGate(size_t gateIdx) const { float delayPerGate = _model->ComputeDelayPerGate(); float age = delayPerGate * gateIdx; float filterWidthInSeconds = delayPerGate; return ComputeValue(age, filterWidthInSeconds); }
/* wrapper for compute_value C code copied from imphttab */ static PyObject * py_compute_value(PyObject *self, PyObject *args) { /* input variables for PhtRow struct */ PyObject *py_row; /* input variables for PhotPar struct */ PyObject *py_par; /* local variables */ int npars; PhtRow row; PhotPar par; double result; /* temporary holder of python object to check for errors */ PyObject *temp_obj; char temp_str[SZ_COLNAME]; /* get input arguments */ if (!PyArg_ParseTuple(args,"OO", &py_row, &py_par)) { return NULL; } /* get how many parameterized variables there are */ temp_obj = PyDict_GetItemString(py_par, "npar"); if (!temp_obj) { PyErr_SetString(PyExc_KeyError, "Key npar not found in par dict."); return NULL; } #if PY_MAJOR_VERSION >= 3 npars = (int) PyLong_AsLong(temp_obj); #else npars = (int) PyInt_AsLong(temp_obj); #endif /* fill PhtRow struct (at least the parts we need) */ if (fill_pht_row(py_row, &row) != 0) { ClosePhotRow(&row); return NULL; } /* fill PhotPar struct (at least the parts we need) */ if (fill_phot_par(py_par, &par) != 0) { ClosePhotRow(&row); FreePhotPar(&par); return NULL; } result = ComputeValue(&row, &par); /* free memory allocated for PhtRow and PhotPar structs */ ClosePhotRow(&row); FreePhotPar(&par); return Py_BuildValue("f",result); }
// ---------------------------------------------------------------------------- // CPcsKeyMap::GetNumericLimitsL // In order to speed up the execution, caller should convert search pattern // with a one call to CPcsKeyMap::GetMappedStringL() and then pass the tokens // to CPcsKeyMap::GetNumericLimitsL(). // So it is expected that aString contains only certain characters. // ---------------------------------------------------------------------------- TInt CPcsKeyMap::GetNumericLimits(QString aString, QString& aLowerLimit, QString& aUpperLimit) const { PRINT(_L("CPcsKeyMap::GetNumericLimits")); if (aString.length() > iMaxKeysStoredInDb) { QString truncated = aString.left(iMaxKeysStoredInDb); aString = truncated; } TInt err = ComputeValue(aString, EFalse, aLowerLimit); if (err == KErrNone) { err = ComputeValue(aString, ETrue, aUpperLimit); } PRINT1(_L("End CPcsKeyMap::GetNumericLimits ret=%d"), err); return err; }
void CGUISlider::AfterUpdate( float elapsedTime ) { m_bChanged = false; if (m_bPushed) { m_bPushed = GetMouse()->IsPressed(0); m_value = ComputeValue(); if (m_value != m_lastValue) { m_bChanged = true; m_lastValue = m_value; } } }
bool CElement::CheckIf(CIfData *pIfData, const CParameters *paParameters) const { if(pIfData->m_Find) { CParameters aSearchParameters; for(CArray<CExpression>::CIterator p = pIfData->m_aSearchParameters.GetIterator(); p.Exists(); p.Next()) aSearchParameters.Add(ComputeValue(p.Get(), paParameters)); CArray<CElement *> apElements; m_pDatabase->SearchElements(pIfData->m_ElementType, pIfData->m_ElementModelName, pIfData->m_SearchFunction, &aSearchParameters, &apElements); bool True = apElements.Size() > 0; #ifdef SPB_DEBUG printf("success: condition find %d\n", True); #endif return True; } else { bool True = ComputeValue(pIfData->m_Expression, paParameters) != 0; #ifdef SPB_DEBUG printf("success: condition %d\n", True); #endif return True; } }
//------------------------- TH1* KVRandomizor::FillHisto2D(Int_t ntimes) //------------------------- { TH2* h1 = new TH2F( Form("histo%dD", fNd), Form("histo%dD", fNd), (fMax[0] - fMin[0]) * 100, fMin[0], fMax[0], (fMax[1] - fMin[1]) * 100, fMin[1], fMax[1] ); for (Int_t ii = 0; ii < ntimes; ii += 1) { fNtest += 1; Double_t* pos = GetPosition(); if (TestValue(ComputeValue(pos))) { h1->Fill(pos[0], pos[1]); } else { ii -= 1; } delete [] pos; } return h1; }
//主函数 int main() { int m; float x; polynomial p1,p2;//建立新链表 p1.head=NULL; p1.tail=NULL; p1.len=0; p2.head=NULL; p2.tail=NULL; p2.len=0; printf("请输入关于x的多项式1中x的最高次幂:"); scanf("%d",&m); if(m<0) { printf("输入值非法!\n"); } CreatePolyn(&p1,m);//创建多项式 printf("多项式1"); PrintPolyn(&p1);//显示多项式1 printf("请输入关于x的多项式2中x的最高次幂:"); scanf("%d",&m); if(m<0) { printf("输入值非法!\n"); } CreatePolyn(&p2,m);//创建多项式 printf("多项式2"); PrintPolyn(&p2);//显示多项式 AddPolyn(&p1,&p2); printf("和多项式"); PrintPolyn(&p1);//输出和多项式 printf("输入x的值:"); scanf("%f",&x); printf("多项式在x=%g时,值为%g",x,ComputeValue(&p1,x));//输出多项式求值 DestroyPolyn(&p1);//销毁多项式 return 0; }
int CiSeries::getLoads() { #ifdef LOADS short ret; if(Globals.nAxesLoadFlag) { ODBSVLOAD sv[MAX_AXIS]; short num = _adapter->_nAxes; GLogger.LogMessage("iSeries::get Loads Enter\n", HEAVYDEBUG); try { ret = cnc_rdsvmeter(_adapter->mFlibhndl, &num, sv); // 15,16,18,21,0,powermate if(ret) { LOGONCE GLogger.Fatal(StdStringFormat("CiSeries::cnc_rdsvmeter Failed\n")); return EW_OK; } if(num>0) _adapter->SetMTCTagValue("Xload",StdStringFormat("%8.4f", ComputeValue(sv[0].svload.data, sv[0].svload.dec))); if(num>1) _adapter->SetMTCTagValue("Yload",StdStringFormat("%8.4f", ComputeValue(sv[1].svload.data, sv[1].svload.dec))); if(num>2) _adapter->SetMTCTagValue("Zload",StdStringFormat("%8.4f", ComputeValue(sv[2].svload.data, sv[2].svload.dec))); for(int i=3; i< _adapter->_nAxes; i++) { if(::toupper(sv[i].svload.name) == 'A') _adapter->SetMTCTagValue("Aload",StdStringFormat("%8.4f", ComputeValue(sv[i].svload.data, sv[i].svload.dec))); if(::toupper(sv[i].svload.name) == 'B') _adapter->SetMTCTagValue("Bload",StdStringFormat("%8.4f", ComputeValue(sv[i].svload.data, sv[i].svload.dec))); if(::toupper(sv[i].svload.name) == 'C') _adapter->SetMTCTagValue("Cload",StdStringFormat("%8.4f", ComputeValue(sv[i].svload.data, sv[i].svload.dec))); } } } catch(...) { } #endif GLogger.Info("CiSeries::get Loads leave\n"); return EW_OK; }
int CiSeries::getPositions() { if (!_adapter->mConnected) return -1; GLogger.LogMessage("iSeries::getPositions Enter\n", HEAVYDEBUG); //ODBPOS *PosData = static_cast<ODBPOS *>(alloca(_nAxes * sizeof(ODBPOS))); /* type. 0 : absolute position 1 : machine position 2 : relative position 3 : distance to go -1 : all type */ short data_num = MAX_AXIS; short type = -1; ODBPOS PosData[MAX_AXIS]; //Position Data short ret = cnc_rdposition(_adapter->mFlibhndl, type, &data_num, &PosData[0]); // 15,16,18,21,0,powermate if (ret == EW_OK) { // Fanuc ABC units are in degrees try { for(int i=0; i< data_num; i++) { GLogger.Info(StdStringFormat( "Axis %c%c%c%c Data=%d Dec=%d\n" , PosData[i].abs.name,(int)PosData[i].abs.data,(int)PosData[i].abs.dec )); if(::toupper(PosData[i].abs.name) == 'X' && i==0) _adapter->SetMTCTagValue("Xabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'Y') _adapter->SetMTCTagValue("Yabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'Z') _adapter->SetMTCTagValue("Zabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'A') _adapter->SetMTCTagValue("Aabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'B') _adapter->SetMTCTagValue("Babs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'C') _adapter->SetMTCTagValue("Cabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'U') _adapter->SetMTCTagValue("Uabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); if(::toupper(PosData[i].abs.name) == 'V') _adapter->SetMTCTagValue("Vabs", StdStringFormat("%8.4f", ComputeValue( PosData[i].abs.data , PosData[i].abs.dec))); } } catch(...) { GLogger.LogMessage("CiSeries::getPositions Exception\n", 3); } //GLogger.LogMessage(StdStringFormat("CiSeries::getPositions %.3f %.3f %.3f\n", // _adapter->mXact.getValue(), _adapter->mYact.getValue(), _adapter->mZact.getValue()) , GLogger.HEAVYDEBUG); } else { _adapter->disconnect(); return -1; } GLogger.LogMessage("iSeries::getPositions Done\n", HEAVYDEBUG); return EW_OK; }
void C3DGORangeWire::OnKillfocusYmax() { ComputeValue(IDC_YMAX); }
void C3DGORangeWire::OnKillfocusYmin() { ComputeValue(IDC_YMIN); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void gosFX::SplineCurve::ComputeRange( Stuff::Scalar *low, Stuff::Scalar *hi ) { Check_Object(this); Check_Pointer(low); Check_Pointer(hi); // //------------------------------------------------------------------------ // We know that we will have to test the function at the beginning and end // of the segment, so go ahead and do that now //------------------------------------------------------------------------ // *hi = *low = m_value; Stuff::Scalar t = ComputeValue(1.0f, 0.0f); if (t>*hi) *hi = t; else if (t<*low) *low = t; // //---------------------------------------------------------------------- // If the curve is not cubic, we just have to look for the local min/max // at the solution to 2*m_b*t + m_slope == 0. If the curve is linear, we just // return //---------------------------------------------------------------------- // if (!m_a) { if (m_b) { t = -0.5f * m_slope / m_b; if (t > 0.0f && t < 1.0f) { t = ComputeValue(t, 0.0f); if (t < *low) *low = t; else if (t > *hi) *hi = t; } } return; } // //---------------------------------------------------------------------- // Now we need to deal with the cubic. Its min/max will be at either of // the two roots of the equation 3*m_a*t*t + 2*m_b*t + m_slope == 0 //---------------------------------------------------------------------- // Stuff::Scalar da = 3.0f*m_a; Stuff::Scalar db = 2.0f*m_b; Stuff::Scalar range = db*db - 4.0f*da*m_slope; if (range < 0.0f) return; da = 0.5f / da; db = -db * da; range = Stuff::Sqrt(range) * da; // //------------------------------------------------------------------------ // db now holds the midpoint between the two solutions, which will be at + // or - range from that point //------------------------------------------------------------------------ // t = db - range; if (t > 0.0f && t < 1.0f) { t = ComputeValue(t, 0.0f); if (t < *low) *low = t; else if (t > *hi) *hi = t; } t = db + range; if (t > 0.0f && t < 1.0f) { t = ComputeValue(t, 0.0f); if (t < *low) *low = t; else if (t > *hi) *hi = t; } }
void CElement::ExecInstructions(const CArray<CInstruction *> *papInstructions, const CParameters *paParameters, bool *pReturned, int *pReturnValue) { *pReturned = false; for(CArray<CInstruction *>::CIterator i = papInstructions->GetIterator(); i.Exists(); i.Next()) { if(m_Removed) break; CInstruction *pBaseInstr = i.Get(); m_pDatabase->SetCurrentInstruction(pBaseInstr->m_LineCount, pBaseInstr->m_Filename); if(pBaseInstr->m_Type == INSTRUCTION_TYPE_SET_ATTRIBUTE) { CSetAttributeInstruction *pInstr = (CSetAttributeInstruction *)pBaseInstr; CAttribute *pAttribute = FindAttribute(pInstr->m_AttributeName); if(!pAttribute) { printf("error: unknown attribute '%s'\n", pInstr->m_AttributeName.GetString()); m_pDatabase->PrintCallstack(); continue; } if(pAttribute->m_Const && pAttribute->m_Defined) { printf("error: attribute const '%s' is already defined\n", pAttribute->m_pName); m_pDatabase->PrintCallstack(); } else { pAttribute->m_Value = ComputeValue(pInstr->m_Value, paParameters); pAttribute->m_Defined = true; #ifdef SPB_DEBUG printf("success: attribute '%s' set to %d\n", pAttribute->m_pName, pAttribute->m_Value); #endif } } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_RETURN) { CReturnInstruction *pInstr = (CReturnInstruction *)pBaseInstr; *pReturned = true; *pReturnValue = ComputeValue(pInstr->m_Value, paParameters); #ifdef SPB_DEBUG printf("success: returned %d\n", *pReturnValue); #endif return; } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_IF) { CIfInstruction *pInstr = (CIfInstruction *)pBaseInstr; bool True = CheckIf(&pInstr->m_IfData, paParameters); if(True) ExecInstructions(&pInstr->m_IfData.m_Instructions.m_apList, paParameters, pReturned, pReturnValue); else { for(CArray<CIfData>::CIterator i = pInstr->m_aElsifDatas.GetIterator(); i.Exists(); i.Next()) { CIfData *pElsifData = &i.Get(); m_pDatabase->SetCurrentInstruction(pElsifData->m_LineCount, pBaseInstr->m_Filename); True = CheckIf(pElsifData, paParameters); if(True) { ExecInstructions(&pElsifData->m_Instructions.m_apList, paParameters, pReturned, pReturnValue); break; } } if(!True) ExecInstructions(&pInstr->m_InstructionsElse.m_apList, paParameters, pReturned, pReturnValue); } if(*pReturned) return; } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_FROM) { CFromInstruction *pInstr = (CFromInstruction *)pBaseInstr; int StartVal = ComputeValue(pInstr->m_StartValue, paParameters); int EndVal = ComputeValue(pInstr->m_EndValue, paParameters); #ifdef SPB_DEBUG printf("success: from %d to %d (reverse %d)\n", StartVal, EndVal, pInstr->m_Reverse); #endif CParameters aFromParameters; paParameters->GetCopy(&aFromParameters); int *pNewParameter = &aFromParameters.Add(); if(pInstr->m_Reverse) { for(int v = StartVal; v >= EndVal; v--) { *pNewParameter = v; ExecInstructions(&pInstr->m_Instructions.m_apList, &aFromParameters, pReturned, pReturnValue); if(*pReturned) return; } } else { for(int v = StartVal; v <= EndVal; v++) { *pNewParameter = v; ExecInstructions(&pInstr->m_Instructions.m_apList, &aFromParameters, pReturned, pReturnValue); if(*pReturned) return; } } } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_CALL_FUNCTION) { CCallFunctionInstruction *pInstr = (CCallFunctionInstruction *)pBaseInstr; CParameters aFunctionParameters; for(CArray<CExpression>::CIterator p = pInstr->m_aFunctionParameters.GetIterator(); p.Exists(); p.Next()) aFunctionParameters.Add(ComputeValue(p.Get(), paParameters)); if(pInstr->m_This) CallFunction(pInstr->m_FunctionName, &aFunctionParameters); else if(pInstr->m_Super) CallFunction(pInstr->m_FunctionName, &aFunctionParameters, true, pInstr->m_Superclass); else { CParameters aSearchParameters; for(CArray<CExpression>::CIterator p = pInstr->m_aSearchParameters.GetIterator(); p.Exists(); p.Next()) aSearchParameters.Add(ComputeValue(p.Get(), paParameters)); CArray<CElement *> apElements; m_pDatabase->SearchElements(pInstr->m_ElementType, pInstr->m_ElementModelName, pInstr->m_SearchFunction, &aSearchParameters, &apElements); for(CArray<CElement *>::CIterator e = apElements.GetIterator(); e.Exists(); e.Next()) { if(!e.Get()->m_Removed) e.Get()->CallFunction(pInstr->m_FunctionName, &aFunctionParameters); } } } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_REMOVE) { CRemoveInstruction *pInstr = (CRemoveInstruction *)pBaseInstr; if(pInstr->m_This) m_pDatabase->RemoveElement(this); else { CParameters aSearchParameters; for(CArray<CExpression>::CIterator p = pInstr->m_aSearchParameters.GetIterator(); p.Exists(); p.Next()) aSearchParameters.Add(ComputeValue(p.Get(), paParameters)); CArray<CElement *> apElements; m_pDatabase->SearchElements(pInstr->m_ElementType, pInstr->m_ElementModelName, pInstr->m_SearchFunction, &aSearchParameters, &apElements); bool DeleteThis = false; for(CArray<CElement *>::CIterator e = apElements.GetIterator(); e.Exists(); e.Next()) { CElement *pElement = e.Get(); if(pElement->m_Removed) continue; if(pElement == this) DeleteThis = true; else m_pDatabase->RemoveElement(pElement); } if(DeleteThis) m_pDatabase->RemoveElement(this); } } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_ADD) { CAddInstruction *pInstr = (CAddInstruction *)pBaseInstr; CParameters aAddParameters; for(CArray<CExpression>::CIterator p = pInstr->m_aAddParameters.GetIterator(); p.Exists(); p.Next()) aAddParameters.Add(ComputeValue(p.Get(), paParameters)); m_pDatabase->AddElement(pInstr->m_ElementType, pInstr->m_ElementModelName, &aAddParameters); } else if(pBaseInstr->m_Type == INSTRUCTION_TYPE_CALL_SYS) { CCallSysInstruction *pInstr = (CCallSysInstruction *)pBaseInstr; CParameters aFunctionParameters; for(CArray<CExpression>::CIterator p = pInstr->m_aFunctionParameters.GetIterator(); p.Exists(); p.Next()) aFunctionParameters.Add(ComputeValue(p.Get(), paParameters)); m_pDatabase->CallSysFunction(pInstr->m_FunctionName, &aFunctionParameters); } } }
void C3DGOAxes::OnKillfocusAngle() { ComputeValue(IDC_ANGLE); }
void C3DGOAxes::OnKillfocusZOrigin() { ComputeValue(IDC_Z_ORIGIN); }