void OperandStack::dcmpl(){ Operand op1H, op1L, op2H, op2L; op2L = pop(); op2H = pop(); op1L = pop(); op1H = pop(); if( (op1H.type != TYPE_DOUBLE) || (op2H.type != TYPE_DOUBLE) ) { printf("Error type not double: :op_stack.dcmpl\n"); exit(0); } double val1, val2; val1 = to_double(op1H.bytes, op1L.bytes); val2 = to_double(op2H.bytes, op2L.bytes); if(isnan(val1) || isnan(val2)) { iconst(-1); return; } if(val1 == val2) iconst(0); else if(val1 > val2) iconst(1); else if(val1 < val2) iconst(-1); }
bool mod_base::checkRange(std::string range, double &val, int *flag) { //take range std::string of form: // {dlow,dhi} // where {} can be replaced by ( ), [ ], ( ], [ ) //parse the std::string vector<std::string> t1 = split(range, ","); if(t1.size()<2) return true; std::string lop, rop, ops, ls, rs; ls = t1.at(0); rs = t1.at(1); lop = ls.at(0); rop = rs.at(rs.size()-1); //Convert range values to doubles double lval, rval; to_double(ls.erase(0,1), &lval); to_double(rs.erase(rs.size()-1,1), &rval); //flags for information to return int tflag=-1; //return the type of range applied (i.e. less than, greater than | less than or equal to, greater than, etc) bool retflag=false; //Is the boundary satisfied? ops = lop+rop; if(ops == " "){return true;} //no info, don't check else if(ops == "()"){if(val > lval && val < rval) {retflag = true; tflag=1;}} else if(ops == "[)"){if(val >= lval && val < rval) {retflag = true; tflag=2;}} else if(ops == "(]"){if(val > lval && val <= rval) {retflag = true; tflag=3;}} else if(ops == "[]"){if(val >= lval && val <= rval) {retflag = true; tflag=4;}} else{retflag = true;} if(flag != NULL) *flag = tflag; return retflag; //boundary not satisfied by any previous consideration }
void OperandStack::drem(){ Operand op1H, op1L, op2H, op2L; op2L = pop(); op2H = pop(); op1L = pop(); op1H = pop(); if( (op1H.type != TYPE_DOUBLE) || (op2H.type != TYPE_DOUBLE) || (op1H.type != TYPE_DOUBLE) || (op2H.type != TYPE_DOUBLE) ) { printf("Error type not double: :op_stack.drem\n"); exit(0); } double val1, val2, val3; val1 = to_double(op1H.bytes, op1L.bytes); val2 = to_double(op2H.bytes, op2L.bytes); val3 = remainder(val1, val2); op1H.set_high(TYPE_DOUBLE, &val3); op1L.set_low(TYPE_DOUBLE, &val3); push(op1H); push(op1L); /*if(size < 4) { printf("Error :op_stack.drem\n"); exit(0); } if( ( (top-1)->bytes == 0x0 ) && (top->bytes==0x0) ) { exception("ArithmeticException: / by zero at OpStack.drem"); } __opDrem(top); top-=2; size-=2;*/ }
void OperandStack::dmul(){ Operand op1H, op1L, op2H, op2L; op2L = pop(); op2H = pop(); op1L = pop(); op1H = pop(); if( (op1H.type != TYPE_DOUBLE) || (op2H.type != TYPE_DOUBLE) || (op1H.type != TYPE_DOUBLE) || (op2H.type != TYPE_DOUBLE) ) { printf("Error type not double: :op_stack.drem\n"); exit(0); } double val1, val2, val3; val1 = to_double(op1H.bytes, op1L.bytes); val2 = to_double(op2H.bytes, op2L.bytes); val3 = val1 * val2; op1H.set_high(TYPE_DOUBLE, &val3); op1L.set_low(TYPE_DOUBLE, &val3); push(op1H); push(op1L); /*if(size < 4) { printf("Error :op_stack.dmul\n"); exit(0); } __dmul(top); top-=2; size-=2;*/ }
void VACExtension::printTightMatrix() { ofstream ofs("problem.dat"); Cost Top = wcsp->getUb(); for (unsigned int i = 0; i < wcsp->numberOfVariables(); i++) { for (unsigned int j = 0; j < wcsp->numberOfVariables(); j++) { if (i != j) { EnumeratedVariable *x = (EnumeratedVariable *) wcsp->getVar(i); EnumeratedVariable *y = (EnumeratedVariable *) wcsp->getVar(j); Constraint *bctr = x->getConstr(y); double t = 0; if (bctr) t = bctr->getTightness(); if (t > to_double(Top)) t = to_double(Top); t = t * 256.0 / to_double(Top); ofs << t << " "; } else ofs << 0 << " "; } ofs << endl; } }
void run_delta_double_bench(struct optics_bench *b, void *data, size_t id, size_t n) { (void) data, (void) id, (void) n; optics_bench_start(b); for (size_t i = 0; i < n; ++i) { double a; { struct timespec ts; clock_monotonic_ptr(&ts); a = to_double(&ts); } double b; { struct timespec ts; clock_monotonic_ptr(&ts); b = to_double(&ts); } double diff = b - a; optics_no_opt_val(diff); } }
int XMIResource::loadPoint(xmlTextReaderPtr reader, const model::BaseObject& o) { assert(o.kind() == LINK); std::vector<double> points; controller.getObjectProperty(o.id(), o.kind(), CONTROL_POINTS, points); // iterate on attributes for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader)) { auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader)); enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found)); switch (current) { case e_x: points.push_back(to_double(xmlTextReaderConstValue(reader))); break; case e_y: points.push_back(to_double(xmlTextReaderConstValue(reader))); break; default: // ignore other parameters // TODO: Does other metamodels might be managed there ? break; } } controller.setObjectProperty(o.id(), o.kind(), CONTROL_POINTS, points); return 1; }
std::size_t hash_value(const CGAL::Point_2<Kernel>& point) { std::size_t seed = 0; boost::hash_combine(seed, to_double(point.x())); boost::hash_combine(seed, to_double(point.y())); return seed; }
Color Texture4D::getNearest(double dx, double dy, double dz, double dw) const { if (dx < 0.0) dx = 0.0; if (dx > 1.0) dx = 1.0; if (dy < 0.0) dy = 0.0; if (dy > 1.0) dy = 1.0; if (dz < 0.0) dz = 0.0; if (dz > 1.0) dz = 1.0; if (dw < 0.0) dw = 0.0; if (dw > 1.0) dw = 1.0; int ix = trunc_to_int(dx * to_double(this->xsize - 1)); int iy = trunc_to_int(dy * to_double(this->ysize - 1)); int iz = trunc_to_int(dz * to_double(this->zsize - 1)); int iw = trunc_to_int(dw * to_double(this->wsize - 1)); assert(ix >= 0 && ix < this->xsize); assert(iy >= 0 && iy < this->ysize); assert(iz >= 0 && iz < this->zsize); assert(iw >= 0 && iw < this->wsize); return this ->data[iw * this->xsize * this->ysize * this->zsize + iz * this->xsize * this->ysize + iy * this->xsize + ix]; }
double TerrainDefinition::getGridHeight(int x, int z, bool with_painting) { double h; if (!with_painting || !has_painting || !height_map->getGridValue(x, z, &h)) { h = _height_noise->get2DTotal(to_double(x), to_double(z)); } return h; }
static void math_atan2(LVGActionCtx *ctx, ASClass *cls, uint8_t *a, uint32_t nargs) { ASVal *se_a = &ctx->stack[ctx->stack_ptr]; ASVal *se_b = se_a + 1; ctx->stack_ptr++; double va = to_double(ctx, se_a); double vb = to_double(ctx, se_b); ASVal *res = &ctx->stack[ctx->stack_ptr]; SET_DOUBLE(res, atan2(va, vb)); }
struct stock convert_to_stock(struct html_table *table) { struct stock _stock = {0}; _stock.sequence = (unsigned int)atoi(table->sequence); memcpy(_stock.exchange, table->exchange, strlen(table->exchange)); memcpy(_stock.board, table->board, strlen(table->board)); memcpy(_stock.time, table->time, strlen(table->time)); memcpy(_stock.paper, table->paper, strlen(table->paper)); _stock.bid = to_double(table->bid); _stock.bid_depth = (unsigned int)atoi(table->bid_depth); _stock.bid_depth_total = (unsigned int)atoi(table->bid_depth_total); _stock.bid_number = (unsigned int)atoi(table->bid_number); _stock.offer = to_double(table->offer); _stock.offer_depth = (unsigned int)atoi(table->offer_depth); _stock.offer_depth_total = (unsigned int)atoi(table->offer_depth_total); _stock.offer_number = (unsigned int)atoi(table->offer_number); _stock.open = to_double(table->open); _stock.high = to_double(table->high); _stock.low = to_double(table->low); _stock.last = to_double(table->last); _stock.change = to_double(table->change); _stock.change_percent = to_double(table->change_percent); _stock.volume = (unsigned int)atoi(table->volume); _stock.value = to_double(table->value); _stock.trades = (unsigned int)atoi(table->trades); return _stock; }
Expression* Expression_lte(Expression* x, Expression* y) { if (x == null || y == null || x->type <= number || y->type <= number) { printf ("Error: lte - invalid arguments"); return nil_; } if (x->type == integer && y->type == integer) { return (*((int*)x->car) <= *((int*)y->car)) ? t_ : nil_; } else if (x->type == real || y->type == real) { return (to_double(x) <= to_double(y)) ? t_ : nil_; } }
/// \brief qll solver // l0 first linear eqn // l1 second linear eqn // xi,yi,ti indexes to shuffle around // xk, yk, kk, rk = params of one ('last') quadratic site (point or arc) // solns = output solution triplets (x,y,t) or (u,v,t) // returns number of solutions found int qll_solver( const std::vector< Eq<qd_real> >& lins, int xi, int yi, int ti, const Eq<qd_real>& quad, qd_real k3, std::vector<Solution>& solns) { assert( lins.size() == 2 ); qd_real ai = lins[0][xi]; // first linear qd_real bi = lins[0][yi]; qd_real ki = lins[0][ti]; qd_real ci = lins[0].c; qd_real aj = lins[1][xi]; // second linear qd_real bj = lins[1][yi]; qd_real kj = lins[1][ti]; qd_real cj = lins[1].c; qd_real d = chop( ai*bj - aj*bi ); // chop! (determinant for 2 linear eqns (?)) if (d == 0) // no solution can be found! return -1; // these are the w-equations for qll_solve() // (2) u = a1 w + b1 // (3) v = a2 w + b2 qd_real a0 = (bi*kj - bj*ki) / d; qd_real a1 = -(ai*kj - aj*ki) / d; qd_real b0 = (bi*cj - bj*ci) / d; qd_real b1 = -(ai*cj - aj*ci) / d; // based on the 'last' quadratic of (s1,s2,s3) qd_real aargs[3][2]; aargs[0][0] = 1.0; aargs[0][1] = quad.a; aargs[1][0] = 1.0; aargs[1][1] = quad.b; aargs[2][0] = -1.0; aargs[2][1] = quad.k; qd_real isolns[2][3]; // this solves for w, and returns either 0, 1, or 2 triplets of (u,v,t) in isolns // NOTE: indexes of aargs shuffled depending on (xi,yi,ti) ! int scount = qll_solve( aargs[xi][0], aargs[xi][1], aargs[yi][0], aargs[yi][1], aargs[ti][0], aargs[ti][1], quad.c, // xk*xk + yk*yk - rk*rk, a0, b0, a1, b1, isolns); double tsolns[2][3]; for (int i=0; i<scount; i++) { tsolns[i][xi] = to_double(isolns[i][0]); // u x tsolns[i][yi] = to_double(isolns[i][1]); // v y tsolns[i][ti] = to_double(isolns[i][2]); // t t chop! solns.push_back( Solution( Point( tsolns[i][0], tsolns[i][1] ), tsolns[i][2], to_double(k3) ) ); } //std::cout << " k3="<<kk3<<" qqq_solve found " << scount << " roots\n"; return scount; }
void test_it() { Q q = CGAL::simplest_rational_in_interval<Q>(-0.1, 0.1); assert(CGAL_NTS is_zero(q)); double l = 3.1415, h = 3.1416; q = CGAL::simplest_rational_in_interval<Q>(l, h); assert(l <= CGAL_NTS to_double(q)); assert(CGAL_NTS to_double(q) <= h); double d = 1234.56789; q = CGAL:: to_rational<Q>(d); assert(CGAL_NTS to_double(q) == d); }
inline double GodRaysSampler::getCache(int x, int y, int z) { double *cache = data + z * samples_x * samples_y + y * samples_x + x; if (*cache < 0.0) { Vector3 location = Vector3(bounds->getStart().x + sampling_step * to_double(x), bounds->getStart().y + sampling_step * to_double(y), bounds->getStart().z + sampling_step * to_double(z)); double unfiltered_power = getRawLight(location, false).getPower(); if (unfiltered_power == 0.0) { *cache = 1.0; } else { *cache = getRawLight(location, true).getPower() / unfiltered_power; } } return *cache; }
void xls_xml_context::characters(const pstring& str, bool transient) { if (str.empty()) return; const xml_token_pair_t& elem = get_current_element(); if (elem.first == NS_xls_xml_ss && elem.second == XML_Data) { switch (m_cur_cell_type) { case ct_string: { if (transient) m_cur_cell_string.push_back(m_pool.intern(str).first); else m_cur_cell_string.push_back(str); } break; case ct_number: { const char* p = str.get(); m_cur_cell_value = to_double(p, p + str.size()); } break; default: ; } } }
toCargs *readArgs(int argc, char *argv[]){ toCargs *pars = new toCargs(); int start = 1; while (start<argc){ if(!strcmp(argv[start],"-g")){ pars->data = readmatrix(argv[start+1]); } else if(!strcmp(argv[start],"-LD")){ pars->LD = atoi( argv[start+1]); } else if(!strcmp(argv[start],"-back")){ pars->back =to_int ( argv[start+1],0,0); } else if(!strcmp(argv[start],"-threshold")){ pars->prune_val =to_double(std::string(argv[start+1])); } else if(!strcmp(argv[start],"-filename")){ pars->data_filename = std::string(argv[start+1]); } else if(!strcmp(argv[start],"-snps")){ pars->usedSnps_filename = std::string(argv[start+1]); } else{ printf("\t->Command line option not recognized: \t%s\n",argv[start]); exit(0); } start+=2; } return pars; }
void RenderProgress::add(int value) { lock->acquire(); global += step * to_double(value); lock->release(); }
int main() { for( std::string str : { "-12345", "0xabcde", "03562", "+23.45", "-0X234P-5", "+INFINITY", "NAN", "abcd", "-1245y", "0xabkde" } ) { std::cout << '\n' << str << " => " ; // try integer try { int v = to_integer(str) ; std::cout << v << " (integer)\n" ; } catch(...) { // not integer, try double try { double v = to_double(str) ; std::cout << v << " (double)\n" ; } // not double catch(...) { std::cout << str << " (string)\n" ; } } } }
void VACExtension::printStat(bool ini) { if (ToulBar2::verbose >= 0) { long double mean = to_double(sumlb) / (long double)nlb; cout << "VAC mean lb/incr: " << mean << " total increments: " << nlb << " cyclesize: " << (double)sumvars / (double)nlb << " k: " << (double)sumk / (double)nlb << " (mean), " << theMaxK << " (max)" << endl; if (ini) cout << "Lb after VAC: " << wcsp->getLb() << endl; } //sort(heap.begin(), heap.end(), cmp_function); /*cout << "Vars: "; vector<tVACStat*>::iterator it = heap.begin(); while(it != heap.end()) { tVACStat* v = *it; if(v->sumlb != MIN_COST) cout << "(" << v->var << "," << v->sumlb << ") "; ++it; } cout << endl; */ sumk = 0; theMaxK = 0; sumvars = 0; sumlb = MIN_COST; nlb = 0; }
bool ResponseReader::read_token(std::string::size_type& start_pos, bool finished, double& result, bool require) throw (P4PProtocolError) { std::string s; bool res = read_token(start_pos, finished, s, require); if (res) result = to_double(s); return res; }
double ConstantGenerator::eval_double(const ExprNode& expr) { Domain d=eval(expr); switch(number_type) { case NEG_INF: return NEG_INFINITY; case POS_INF: return POS_INFINITY; default: return to_double(d); //eval(expr)); } }
RenderProgress::RenderProgress(int count) { lock = new Mutex(); global = 0.0; step = 1.0 / to_double(count); start_time = 0; end_time = 0; reset(); }
int main(){ AK ak; // an object of AK::Construct_algebraic_real_1 construct_algreal_1 = ak.construct_algebraic_real_1_object(); std::cout << "Construct from int : " << construct_algreal_1(int(2)) << "\n"; std::cout << "Construct from Coefficient : " << construct_algreal_1(Coefficient(2)) << "\n"; std::cout << "Construct from Bound : " << construct_algreal_1(Bound(2)) << "\n\n"; Polynomial_1 x = CGAL::shift(AK::Polynomial_1(1),1); // the monomial x std::cout << "Construct by index : " << construct_algreal_1(x*x-2,1) << "\n" << to_double(construct_algreal_1(x*x-2,1)) << "\n"; std::cout << "Construct by isolating interval : " << construct_algreal_1(x*x-2,Bound(0),Bound(2)) << "\n" << to_double(construct_algreal_1(x*x-2,Bound(0),Bound(2))) << "\n\n"; return 0; }
static void shape_cb(gen_ptr g, void *data) { stomperosc_data_ptr p; p = (stomperosc_data_ptr) g->data; p->exp = double_clip(to_double(data), 0.0, 100.0); //Stomper acts strangely for square waves //turns 0 to 100 into the duty cycle //with 0-->0, 1-->0.5, 100-->1 p->duty = pow(p->exp * 0.01, LOG2OVERLOG100); }
int XMIResource::loadDoubleArray(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o) { std::vector<double> v; controller.getObjectProperty(o.id(), o.kind(), property, v); v.push_back(to_double(xmlTextReaderConstValue(reader))); controller.setObjectProperty(o.id(), o.kind(), property, v); return 1; }
Expression* Expression_sub(Expression* x, Expression* y) { ExpressionType type = (x->type == real || y->type == real) ? real : integer; void* p; if (type == integer) { int* result = malloc(sizeof(int)); *result = *((int*)x->car) - *((int*)y->car); p = (void*)result; } else if (type == real) { double* result = malloc(sizeof(double)); *result = to_double(x) - to_double(y); p = (void*)result; } _gc_protect(x); _gc_protect(y); Expression* z = _new_Expression(type); _gc_unprotect(y); _gc_unprotect(x); z->car = p; return z; }
int main(int argc, const char * argv[]) { char test[420]; printf("Enter a smallish number: "); scanf("%[^\n]%*c", test); if (is_valid_int(test)) modtest(to_int(test)); printf("\n%d\t%d\n",is_valid_int(test),to_int(test)); printf("%d\t%g\n",is_valid_number(test),to_double(test)); return 420; }
void cls_op::do_process(const tuple_ptr tup, int) { pre_process_hook(tup); std::vector<double> coordinates = std::vector<double>(m_value_d); for (int i = 0; i < m_value_d; i++) coordinates[i] = to_double((*tup)[i]); long timestamp = to_long(tup->op_arrival_time()); std::vector<cls_snapshot_microcluster*> *smc = m_clustream->process(coordinates, timestamp); if (smc != NULL) { cls_lbgu *lbgu = new cls_lbgu(smc, m_value_k); lbgu->start(); std::vector<cls_cluster*> result = lbgu->get_clusters(); std::vector<std::pair<int, cls_cluster*> > result_list(0); for (int i = 0; i < m_value_k; i++) result_list.push_back(std::pair<int, cls_cluster*>(i, result[i])); m_id++; if (m_first_output_done) { m_new_list = sort_clusters(m_old_list, result_list); m_difference = calculate_difference(m_old_list, m_new_list); } else { m_new_list = result_list; m_difference = result_list; m_first_output_done = true; } std::vector<std::pair<int, cls_cluster*> > output_list; if (m_output_version == 0) output_list = m_new_list; else if (m_output_version == 1) output_list = m_difference; else output_list = m_new_list; for (int i = 0; i < (int) output_list.size(); i++) { std::vector<boost::any> data(2 + m_value_d); data[0] = m_id; data[1] = output_list[i].first; for (int j = 0; j < m_value_d; j++) data[j+2] = output_list[i].second->get_coordinate(j); tuple_ptr n_tuple(new tuple(data)); publish_new(n_tuple); } m_old_list = m_new_list; } }