double difb2(double x, double h) { double f1, f2; f1 = _f(x - h) - _f(x); f2 = _f(x - 2. * h) - _f(x); return - (2. * f1 - 0.5 * f2) / h; }
double diff2(double x, double h) { double f1, f2; f1 = _f(x + h) - _f(x); f2 = _f(x + 2. * h) - _f(x); return (2. * f1 - 0.5 * f2) / h; }
double diff5(double x, double h) { double f1, f2, f3, f4, f5; f1 = _f(x + h) - _f(x); f2 = _f(x + 2. * h) - _f(x); f3 = _f(x + 3. * h) - _f(x); f4 = _f(x + 4. * h) - _f(x); f5 = _f(x + 5. * h) - _f(x); return (5. * (f1 - f2) + 10. * f3 / 3. - 1.25 * f4 + 0.2 * f5) / h; }
double difb5(double x, double h) { double f1, f2, f3, f4, f5; f1 = _f(x - h) - _f(x); f2 = _f(x - 2. * h) - _f(x); f3 = _f(x - 3. * h) - _f(x); f4 = _f(x - 4. * h) - _f(x); f5 = _f(x - 5. * h) - _f(x); return - (5. * (f1 - f2) + 10. * f3 / 3. - 1.25 * f4 + 0.2 * f5) / h; }
TreeNode *_f(TreeNode *root) { if (root->left == NULL && root->right == NULL) { return root; } TreeNode *L = NULL, *R = NULL; if (root->left != NULL) L = _f(root->left); if (root->right != NULL) R = _f(root->right); if (L == NULL) return R; L->right = root->right; root->right = root->left; root->left = NULL; return R == NULL ? L : R; }
inttype go(inttype n) { inttype x,y,d=1; x=y=Rand()%n; while(d==1) { x=_f(x,n); y=_f(_f(y,n),n); d=gcd(g::abs(y-x),n); } if(d!=n)return d; return d; }
VariableHolder::Callable const& VariableHolder::for_each_argument(Callable const& _f) const { args_ordered_t::const_iterator end = DATA->args_ordered.end(); bool more = true; for (args_ordered_t::const_iterator ite = DATA->args_ordered.begin(); more && ite != end; ++ite) more = _f(*ite); return _f; }
void TaskThreadPool::init( unsigned int max_count, const std::string& name ) { for ( unsigned int i = 0; i < max_count; ++i ) { _threads.emplace_back( [=]() { ThreadRegister register_thread( "TaskPool " + name ); auto f = msg(); try { while ( !_done ) { _msg_queue.pop_wait( &f ); f(); } } catch ( msg_queue::Canceled& ) { } catch ( std::exception& ex ) { ERROR_PRINT << "Thread exception: " << ex.what() << "\n"; Clib::force_backtrace( true ); return; } // purge the queue empty std::list<msg> remaining; _msg_queue.pop_remaining( &remaining ); for ( auto& _f : remaining ) _f(); } ); } }
QString ShaderCompiler::compileRecursive(QString const& _sourceFile, std::set<QString>& _includedFiles) { if (_includedFiles.count(_sourceFile) > 0) return QString(); QFile _f(_sourceFile); _includedFiles.insert(_sourceFile); QString _outputFile; if (_f.open(QIODevice::ReadOnly)) { QTextStream in(&_f); while (!in.atEnd()) { QString _line = in.readLine().trimmed(); if (_line.startsWith("#include")) { // Handle include auto _includedFilename = parseIncludeLine("",_line); _outputFile += compileRecursive(_includedFilename,_includedFiles); } else { _outputFile += _line + '\n'; } } _f.close(); } return _outputFile; }
bool PickHandler::handle(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa) { if (!_f) return false; if (ea.getEventType() != osgGA::GUIEventAdapter::RELEASE || ea.getButton() != osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) return false; osgViewer::Viewer * viewer = dynamic_cast<osgViewer::Viewer*>(&aa); if (viewer) { osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector( osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()); osgUtil::IntersectionVisitor iv(intersector.get()); iv.setTraversalMask(~0x1); viewer->getCamera()->accept(iv); if (intersector->containsIntersections()) { const osgUtil::LineSegmentIntersector::Intersection &result = *(intersector->getIntersections().begin()); _f(result); } } return false; }
bool EpisodeState::load() { QString file= _episodePath+saveFileName; QFile _f(file); if(!_f.exists(file)) return false; if (_f.open(QIODevice::ReadOnly)) { QString fileRaw; QTextStream inStr(&_f); GamesaveData FileData; inStr.setCodec("UTF-8"); fileRaw = inStr.readAll(); FileData = FileFormats::ReadExtendedSaveFile(fileRaw, file); if(FileData.ReadFileValid) { game_state = FileData; episodeIsStarted=true; return true; } else { PGE_MsgBox::error(file+"\n"+FileFormats::errorString); } } return false; }
/// Return content of file from a file name QString fileToStr(const QString& _filename) { QFile _f(_filename); _f.open(QIODevice::ReadOnly | QIODevice::Text); return _f.readAll(); }
void sipg_sem_1d<FLOAT_TYPE>::compute_rhs_vector() { compute_nodes_and_weights(); const int nop = sem_function<FLOAT_TYPE>::_qt.nop(); const int M = nop-1; //< index of the right node //< 0 is the index of the left node _rhs.resize(_vec_size); for (int i = 0; i < _vec_size; ++i) _rhs[i] = _w[i] * _f(_x[i]); // this loop add the nitsche border integral term to the first // and the last elements // -1 +-----+- ... -+-----+ +1 for (int i=0; i < nop; ++i) { _rhs[i] += _noe*SEM_FUNC::d_phi(i,0)*_u_ex(-1.); _rhs[_vec_size - nop + i] += -1*_noe*SEM_FUNC::d_phi(i,M)*_u_ex( 1.); } _rhs[0] += _pen*_u_ex(-1.); _rhs[_vec_size-1] += _pen*_u_ex( 1.); }
/*! * calculates the value of the function at the specified point, * \p p, and time, \p t, and returns it in \p v. */ virtual void derivative (const MAST::FunctionBase& f, const libMesh::Point& p, const Real t, Real& v) const { Real dp = 0., df = 0.; // if the sensitivity parameter is the load parameter itself, // then the sensitivity parameter will be nonzero. if (_p.depends_on(f)) dp = 1.; if (_f.depends_on(f)) df = 1.; v = dp * sin(_f()*t) + _p() * _f() * df * cos(_f() * t); }
double difb4(double x, double h) { double f1, f2, f3, f4; f1 = _f(x - h) - _f(x); f2 = _f(x - 2. * h) - _f(x); f3 = _f(x - 3. * h) - _f(x); f4 = _f(x - 4. * h) - _f(x); return - (4. * f1 - 3. * f2 + 4. * f3 / 3. - 0.25 * f4) / h; }
double diff4(double x, double h) { double f1, f2, f3, f4; f1 = _f(x + h) - _f(x); f2 = _f(x + 2. * h) - _f(x); f3 = _f(x + 3. * h) - _f(x); f4 = _f(x + 4. * h) - _f(x); return (4. * f1 - 3. * f2 + 4. * f3 / 3. - 0.25 * f4) / h; }
void PcapReader:: handlePacket(char* buff_, uint64_t blen_) { struct ether_header* ethHdr; struct ip* ipHdr; struct udphdr* udpHdr; uint64_t slen; // Read ether_header slen = sizeof(struct ether_header); if (blen_<slen) { std::cout << "PcapReader::handlePacket. PacketLen less than ether_header" << std::endl; return; } ethHdr = reinterpret_cast<struct ether_header*>(buff_); if (ethHdr->ether_type != 0x08) { // std::cout << "handlePacket. ether_type: " << ethHdr->ether_type << ", " << (uint16_t)ETHERTYPE_IP << std::endl; return; } blen_ -= slen; buff_ = (char*)(buff_+slen); // Read ip header // We handle only UDP packets if (blen_<sizeof(struct ip)) { std::cout << "PcapReader::handlePacket. PacketLen less than struct ip" << std::endl; return; } ipHdr = reinterpret_cast<struct ip*>(buff_); slen = ipHdr->ip_hl*4; // header length in 4 bytes words if (blen_<slen) { std::cout << "PcapReader::handlePacket. PacketLen less than struct ip.hl: " << slen << std::endl; return; } if (ipHdr->ip_p != IPPROTO_UDP) { std::cout << "PcapReader::handlePacket. Not UDP protocol. proto: " << (int)ipHdr->ip_p << std::endl; return; } blen_ -= slen; buff_ = (char*)(buff_+slen); // Read UDP header slen = sizeof(struct udphdr); udpHdr = reinterpret_cast<struct udphdr*>(buff_); blen_ -= slen; buff_ = (char*)(buff_+slen); // firing cb if (_f != nullptr) { _f(buff_, blen_); } }
const ValueType& operator*() const { if (!_value_valid) { _value = _f(_n); _value_valid = true; } return _value; }
void do_call(std::vector<boost::any> const& v, std::integer_sequence<int, Is...>) { try { return _f((get_ith<Args>(v, Is))...); } catch (boost::bad_any_cast const&) { std::cout << "Bad argument!" << std::endl; // Throw if you prefer } }
// implementation: function value & gradient tscalar _f(const tvector& x, tvector& g) const { if (m_op_grad) { m_n_fvals ++; m_n_grads ++; return m_op_grad(x, g); } else { eval_grad(x, g); return _f(x); } }
double diff3(double x, double h) { double f1, f2, f3; f1 = _f(x + h) - _f(x); f2 = _f(x + 2. * h) - _f(x); f3 = _f(x + 3. * h) - _f(x); return (3. * f1 - 1.5 * f2 + f3 / 3.) / h; }
double difb3(double x, double h) { double f1, f2, f3; f1 = _f(x - h) - _f(x); f2 = _f(x - 2. * h) - _f(x); f3 = _f(x - 3. * h) - _f(x); return - (3. * f1 - 1.5 * f2 + f3 / 3.) / h; }
menuItem* enterShutterSpeed::do_action() { display *lcd; int8_t speed_index; uint16_t speed; uint8_t button; lcd = get_display(); get_question(buffer); speed_index = *_speed_index; do { lcd->clear(); lcd->print(buffer); lcd->setCursor(0, 2); if(speed_index < 0) { lcd->print("1/"); } speed = _shutter_speeds[abs(speed_index)]; lcd->print(speed/10); if(speed%10) { lcd->print("."); lcd->print(speed%10); } // wait for some useful key do{ button = buttons_reader.read(); } while(button == IDLE); if(button == UP && speed_index < _shutter_speeds_count - 1) { speed_index++; } else if(button == DOWN && speed_index > 1 - _shutter_speeds_count) { speed_index--; } if(_f) { _f(speed_index); } } while(button == UP || button == DOWN); // if not "cancel", save value if(button != LEFT) { *_speed_index = speed_index; } return 0; }
void addAtlas(const char *file){ tinyxml2::XMLDocument doc; doc.LoadFile(_f(file)); const tinyxml2::XMLElement *pElem = doc.RootElement(); pElem = pElem->FirstChildElement("image"); while ( pElem ){ const char *name = pElem->Attribute("name"); AtlasInfo atlas; atlas.file = pElem->Attribute("file"); pElem->QueryIntAttribute("x", &atlas.u); pElem->QueryIntAttribute("y", &atlas.v); pElem->QueryIntAttribute("w", &atlas.w); pElem->QueryIntAttribute("h", &atlas.h); _atlasMap[name] = atlas; pElem = pElem->NextSiblingElement(); } }
menuItem* enterNumberItem::do_action() { display *lcd; int value; uint8_t button; lcd = get_display(); get_question(buffer); value = *_variable; do { lcd->clear(); lcd->print(buffer); lcd->setCursor(0, 2); lcd->print(value); // wait for some useful key do{ button = buttons_reader.read(); } while(button == IDLE); if(button == UP) { value += _step; } else if(button == DOWN) { value -= _step; if(value < 0) { value = 0; } } if(_f) { _f(value); } } while(button == UP || button == DOWN); // if not "cancel", save value if(button != LEFT) { *_variable = value; } return 0; }
TextureRes::TextureRes(const char* fileName, bool reserveData, bool revertY) : _glId(-1), _pImgData(NULL){ lwassert(fileName); _fileName = fileName; size_t len = strlen(fileName); if ( len < 4 ){ lwerror("texture file name too short: filepath = " << _f(fileName)); _glId = -1; return; } _f fpath(fileName); if ( fileName[len-4] == '.' && fileName[len-3] == 'p' && fileName[len-2] == 'n' && fileName[len-1] == 'g'){ if ( fpath.isValid() ){ loadPNG(fpath, reserveData); }else{ lwerror("texture is not exist: " << fileName); return; } }else{ lwerror("only support PNG file: " << fileName); return; } }
virtual void do_oop(oop* o) { _f(o); }
void call_func(Tuple t, std::index_sequence<Indices...> s) { _f(boost::any_cast<typename std::tuple_element<Indices, Params>::type>(std::get<Indices>(t))...); }
void Utils::ThreadUnix::ThreadBasicLauncher::operator()(void *arg) { _f(arg); }
/* * \param t The value of type T * * Functor \a f will be applied to \a t and the resulting value used * for comparison. */ virtual bool operator()(T& t) const { return (find(_list.begin(), _list.end(), _f(t)) != _list.end()); }