void ovm_q_mul(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->t = t_word; l->v.w = 0; break; case t_word: mpq_set_si(oqr(r), r->v.w, 1); mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_float: l->t = t_float; l->v.d = mpq_get_d(oqr(l)) * r->v.d; break; case t_mpz: mpz_set_ui(ozs(r), 1); mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_rat: mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_mpq: mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_mul(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: l->t = t_cdd; l->v.dd = mpq_get_d(oqr(l)) * r->v.dd; check_cdd(l); break; case t_cqq: l->t = t_cqq; mpq_set_ui(oqi(l), 0, 1); cqq_mul(oqq(l), oqq(l), oqq(r)); check_cqq(l); break; case t_mpc: l->t = t_mpc; mpc_set_q(occ(l), oqr(l), thr_rndc); mpc_mul(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
void ovm_dd_hypot(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->t = t_float; l->v.d = cabs(l->v.dd); break; case t_word: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), r->v.w); break; case t_float: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), r->v.d); break; case t_mpz: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), mpz_get_d(ozr(r))); break; case t_rat: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), rat_get_d(r->v.r)); break; case t_mpq: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), mpq_get_d(oqr(r))); break; case t_mpr: mpc_set_fr(occ(r), orr(r), thr_rndc); goto mpc; case t_cdd: cdd: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), hypot(real(r->v.dd), imag(r->v.dd))); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; case t_mpc: mpc: l->t = t_mpr; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpfr_hypot(orr(l), orr(l), ori(l), thr_rnd); mpfr_hypot(ori(l), orr(r), ori(r), thr_rnd); mpfr_hypot(orr(l), orr(l), ori(l), thr_rnd); break; default: ovm_raise(except_not_a_number); } }
void Word::addNewOccurrenc(string url){ Occurence occ(url); BSTNode<Occurence> * nodeOcc = NULL; nodeOcc = occurences.Find(occ); if(nodeOcc != NULL){ nodeOcc->GetValue().addCount(); }else{ Occurence occ(url); occurences.Insert(occ); } }
void ovm_dd_pow(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->t = t_float; l->v.d = 1.0; break; case t_word: real(r->v.dd) = r->v.w; imag(r->v.dd) = 0.0; goto cdd; case t_float: real(r->v.dd) = r->v.d; imag(r->v.dd) = 0.0; goto cdd; case t_mpz: real(r->v.dd) = mpz_get_d(ozr(r)); imag(r->v.dd) = 0.0; goto cdd; case t_rat: real(r->v.dd) = rat_get_d(r->v.r); imag(r->v.dd) = 0.0; goto cdd; case t_mpq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; case t_mpr: mpc_set_fr(occ(r), orr(r), thr_rndc); goto mpc; case t_cdd: cdd: l->v.dd = cpow(l->v.dd, r->v.dd); check_cdd(l); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; case t_mpc: mpc: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_pow(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
void ovm_dd_mul(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->v.dd *= 0.0; check_cdd(l); break; case t_word: l->v.dd *= r->v.w; check_cdd(l); break; case t_float: l->v.dd *= r->v.d; check_cdd(l); break; case t_mpz: l->v.dd *= mpz_get_d(ozr(r)); check_cdd(l); break; case t_rat: l->v.dd *= rat_get_d(r->v.r); check_cdd(l); break; case t_mpq: l->v.dd *= mpq_get_d(oqr(r)); check_cdd(l); break; case t_mpr: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_set_fr(occ(r), orr(r), thr_rndc); mpc_mul(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; case t_cdd: l->v.dd *= r->v.dd; check_cdd(l); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); l->v.dd *= r->v.dd; check_cdd(l); break; case t_mpc: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_mul(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
/** * pos is a fpos */ unsigned long decode_backward_until(bwttext * t, unsigned long pos, unsigned char until, int inclusive, strbuf * sb) { character * ch; unsigned char c; unsigned long p = pos; do { // p is a fpos; it gets its previous char in the the last column fseek(t->fp, p + 4, SEEK_SET); fread(&c, sizeof (unsigned char), 1, t->fp); // the char should exist ch = t->char_hash[(unsigned int) c]; if (ch == NULL) { fprintf(stderr, "\nerror: char code=%d\n", c); break; // error } // output the char if (until != c || inclusive) strbuf_putchar(sb, c); // figure out the fpos of the char p = ch->ss + occ(t, c, p); // break the loop if it meets the char until if (until == c) break; // stop when the previous char is the final end // (looping back to the end) } while (p != t->end); // note that it is ensured to output an fpos return p; }
void ovm_dd_atan2(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: goto flt; case t_word: if (r->v.w) { real(r->v.dd) = r->v.w; imag(r->v.dd) = 0.0; goto cdd; } flt: l->t = t_float; l->v.d = real(l->v.dd) >= 0.0 ? M_PI_2 : -M_PI_2; break; case t_float: if (r->v.d) { real(r->v.dd) = r->v.d; imag(r->v.dd) = 0.0; goto cdd; } goto flt; case t_mpz: real(r->v.dd) = mpz_get_d(ozr(r)); imag(r->v.dd) = 0.0; goto cdd; case t_rat: real(r->v.dd) = rat_get_d(r->v.r); imag(r->v.dd) = 0.0; goto cdd; case t_mpq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; case t_mpr: mpc_set_fr(occ(r), orr(r), thr_rndc); goto mpc; case t_cdd: cdd: l->v.dd = catan(l->v.dd / r->v.dd); check_cdd(l); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; case t_mpc: mpc: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_div(occ(l), occ(l), occ(r), thr_rndc); mpc_atan(occ(l), occ(l), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
fpos_range * search_forward(bwttext * t, unsigned char * p, unsigned int l) { fpos_range * r; unsigned long o, fp, lp, tp; character * ch; unsigned char x; int pp, tpp; if (l < 1) return NULL; r = (fpos_range *) malloc(sizeof (fpos_range)); pp = 0; while (pp < l) { x = p[pp++]; ch = t->char_hash[x]; if (ch == NULL) { free(r); return NULL; } o = char_freq(t, ch) - 1; fp = ch->ss; lp = ch->ss + o; tpp = pp - 2; while (tpp >= 0) { ch = t->char_hash[p[tpp--]]; tp = ch->ss + occ(t, ch->c, fp); lp = ch->ss + occ(t, ch->c, lp + 1) - 1; if (tp == lp + 1 && tp < fp) { free(r); return NULL; } fp = tp; } r->first = fp; r->last = lp; } return r; }
void partitionedGenerateLevels( uint32_t seed, const uint32_t partitionStartIndex, const uint32_t partitionEndIndex ) { OcclusionBuffer occ(TILE_DIM, TILE_DIM); for( uint32_t i = partitionStartIndex ; i < partitionEndIndex ; ++i ) { occ.Clear(); uint32_t roomsAdded = 0; for( uint32_t ii = 0 ; ii < 50000 ; ii++ ) { roomsAdded += static_cast<size_t>(makeRoomSilentlyFail( levels_[i], seed, occ )); if (roomsAdded == 99) break; } levels_[i].fillTiles(); } }
fpos_range * search_backward(bwttext * t, unsigned char * p, unsigned int l) { fpos_range * r; character * c; unsigned int pp; unsigned char x; pp = l - 1; x = p[pp]; c = t->char_hash[(unsigned int) x]; if (c == NULL) return NULL; r = (fpos_range *) malloc(sizeof (fpos_range)); r->first = c->ss; r->last = r->first + char_freq(t, c) - 1; //printf("%c: %lu, %lu\n", x, r->first, r->last); while (r->first <= r->last && pp > 0) { x = p[--pp]; c = t->char_hash[(unsigned int) x]; if (c == NULL) { free(r); return NULL; } //printf("[%lu, %lu, %lu]\n", c->ss, occ(t, x, r->first), occ(t, x, r->last + 1) - 1); r->first = c->ss + occ(t, x, r->first); r->last = c->ss + occ(t, x, r->last + 1) - 1; //printf("%c: %lu, %lu\n\n", x, r->first, r->last); } if (r->first <= r->last) return r; free(r); return NULL; }
static void eval_fetch(oobject_t *p) { oregister_t *r; oobject_t v; r = &thread_main->r0; switch (r->t) { case t_void: *p = null; break; case t_word: oget_word(p); v = *p; *(oword_t *)v = r->v.w; break; case t_float: oget_float(p); v = *p; *(ofloat_t *)v = r->v.d; break; case t_rat: oget_rat(p); v = *p; *(orat_t )v = r->v.r; break; case t_mpz: oget_mpz(p); v = *p; mpz_set((ompz_t)v, ozr(r)); break; case t_mpq: oget_mpq(p); v = *p; mpq_set((ompq_t)v, oqr(r)); break; case t_mpr: oget_mpr(p); v = *p; mpfr_set((ompr_t)v, orr(r), thr_rnd); break; case t_cdd: oget_cdd(p); v = *p; *(ocdd_t *)v = r->v.dd; break; case t_cqq: oget_cqq(p); v = *p; cqq_set((ocqq_t)v, oqq(r)); break; default: assert(r->t == t_mpc); oget_mpc(p); v = *p; mpc_set((ompc_t)v, occ(r), thr_rndc); break; } }
void SpinAdapted::Slater::outerProd(const Slater& s, Slater& output) const { vector<bool> occ(Slater().size()); for (int i=0; i<Slater().size(); i++) { if (s.alpha.get_occ_rep()[i] == 1 && alpha.get_occ_rep()[i]==1) { cout <<"cannot get outerprod of slater determinants\ndet1: "<<s<<"\ndet2: "<<*this<<endl; throw 20; } occ[i] = s.alpha.get_occ_rep()[i] + alpha.get_occ_rep()[i]; } Orbstring o(occ, s.alpha.getSign()*alpha.getSign()); Slater temp(o); output = temp; }
/** * not in-use: backward decoding reverses data; * but essentially this is the algorithm */ void decode_backward(bwttext * t, FILE * fout) { unsigned char c; character * ch; unsigned long p = t->end; do { fseek(t->fp, p + 4, SEEK_SET); fread(&c, sizeof (unsigned char), 1, t->fp); ch = t->char_hash[(unsigned int) c]; if (ch == NULL) { fprintf(stderr, "\nerror: char code=%d\n", c); break; // error } //putchar(c); fputc(c, fout); p = ch->ss + occ(t, c, p); } while (p != t->end); }
static void eval_setup(oregister_t *r, oobject_t v) { if (v == null) { r->t = t_void; r->v.o = null; } else { switch (r->t = otype(v)) { case t_word: r->v.w = *(oword_t *)v; break; case t_float: r->v.d = *(ofloat_t *)v; break; case t_rat: r->v.r = *(orat_t)v; break; case t_mpz: mpz_set(ozr(r), (ompz_t)v); break; case t_mpq: mpq_set(oqr(r), (ompq_t)v); break; case t_mpr: mpfr_set(orr(r), (ompr_t)v, thr_rnd); break; case t_cdd: r->v.dd = *(ocdd_t *)v; break; case t_cqq: cqq_set(oqq(r), (ocqq_t)v); break; default: assert(r->t == t_mpc); mpc_set(occ(r), (ompc_t)v, thr_rndc); break; } } }
void construct() { P.push_back(vi(n, 0)); compress(); vi occ(n + 1, 0), s1(n, 0), s2(n, 0); for (int k = 1, cnt = 1; cnt / 2 < n; ++k, cnt *= 2) { P.push_back(vi(n, 0)); fill(occ.begin(), occ.end(), 0); for (int i = 0; i < n; ++i) occ[i+cnt<n ? P[k-1][i+cnt]+1 : 0]++; partial_sum(occ.begin(), occ.end(), occ.begin()); for (int i = n - 1; i >= 0; --i) s1[--occ[i+cnt<n ? P[k-1][i+cnt]+1 : 0]] = i; fill(occ.begin(), occ.end(), 0); for (int i = 0; i < n; ++i) occ[P[k-1][s1[i]]]++; partial_sum(occ.begin(), occ.end(), occ.begin()); for (int i = n - 1; i >= 0; --i) s2[--occ[P[k-1][s1[i]]]] = s1[i]; for (int i = 1; i < n; ++i) { P[k][s2[i]] = same(s2[i], s2[i - 1], k, cnt) ? P[k][s2[i - 1]] : i; } } }
void decode_backward_rev(bwttext * t, FILE * fout) { character * ch; unsigned char c; unsigned long p, dp; unsigned char buf[BUF_SIZE]; int bufcur; p = t->end; // start from the last buf if (t->file_size > BUF_SIZE) dp = t->file_size - BUF_SIZE; else dp = 0; fseek(fout, dp, SEEK_SET); bufcur = BUF_SIZE - 1; do { // read fseek(t->fp, p + 4, SEEK_SET); fread(&c, sizeof (unsigned char), 1, t->fp); buf[bufcur--] = c; // write by buf if (bufcur == -1) { // buf is just full fwrite(buf, sizeof (unsigned char), BUF_SIZE, fout); bufcur = BUF_SIZE - 1; // start of next buf if (dp >= BUF_SIZE) { fseek(fout, -BUF_SIZE * 2, SEEK_CUR); dp -= BUF_SIZE; } else { fseek(fout, 0, SEEK_SET); dp = 0; } } // write by char //fputc(c, fout); //fseek(fout, -2, SEEK_CUR); //dp--; ch = t->char_hash[(unsigned int) c]; // nothing but error detection if (ch == NULL || dp < 0) { // TODO well, dp is unsigned... fprintf(stderr, "\nerror: char code=%d\n, bwt pos=%lu, dest pos=%lu", c, p, dp); break; // error } // next position p = ch->ss + occ(t, c, p); } while (p != t->end); // flush buf if (bufcur < BUF_SIZE - 1) // something's in buf if cursor is before the very end fwrite(&buf[bufcur + 1], sizeof (unsigned char), BUF_SIZE - 1 - bufcur, fout); }
void ovm_q_hypot(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: if (!cfg_float_format) { l->t = t_float; l->v.d = fabs(mpq_get_d(oqr(l))); } else { mpfr_set_ui(orr(r), 0, thr_rnd); goto mpr; } break; case t_word: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), r->v.w); } else { mpfr_set_si(orr(r), r->v.w, thr_rnd); goto mpr; } break; case t_float: l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), mpz_get_d(ozr(r))); } else { mpfr_set_z(orr(r), ozr(r), thr_rnd); goto mpr; } break; case t_rat: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), rat_get_d(r->v.r)); } else { mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpq: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), mpq_get_d(oqr(r))); } else { mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpr: mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_hypot(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: cdd: l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), hypot(real(r->v.dd), imag(r->v.dd))); break; case t_cqq: if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; } mpc_set_q_q(occ(r), oqr(r), oqi(r), thr_rndc); case t_mpc: l->t = t_mpr; mpc_set_q(occ(l), oqr(l), thr_rndc); mpfr_hypot(ori(l), orr(l), ori(l), thr_rnd); mpfr_hypot(orr(l), orr(r), ori(r), thr_rnd); mpfr_hypot(orr(l), ori(l), orr(l), thr_rnd); break; default: ovm_raise(except_not_a_number); } }
Word::Word(string val, string url){ this->Value = val; Occurence occ(url); occurences.Insert(occ); }
//--------------------------------------------------------------------------- int XsltPolicy::parse_policy_rule(xmlNodePtr node, bool is_root, XsltPolicy* current) { XsltPolicyNode *new_node = NULL; if (is_root) { error = "Policy has to start with a policy node"; return -1; } else { new_node = new XsltPolicyRule; ((XsltPolicyRule*)new_node)->id = ((XsltPolicyRule*)new_node)->rule_id++; new_node->parent_id = current->id; current->nodes.push_back(new_node); } new_node->kind = XSLT_POLICY_RULE; XsltPolicyRule *r = (XsltPolicyRule*)new_node; //Get name xmlChar *name = xmlGetNoNsProp(node, (const unsigned char*)"name"); if (name) { r->node_name = std::string((const char*)name); xmlFree(name); } //Get ope xmlChar *ope = xmlGetNoNsProp(node, (const unsigned char*)"operator"); if (ope) { r->ope = std::string((const char*)ope); xmlFree(ope); } //Get trackType xmlChar *track_type = xmlGetNoNsProp(node, (const unsigned char*)"tracktype"); if (track_type) { r->track_type = std::string((const char*)track_type); xmlFree(track_type); } //Get field xmlChar *field = xmlGetNoNsProp(node, (const unsigned char*)"value"); if (field) { r->field = std::string((const char*)field); xmlFree(field); } //Get scope xmlChar *scope = xmlGetNoNsProp(node, (const unsigned char*)"scope"); if (scope) { r->scope = std::string((const char*)scope); xmlFree(scope); } //Get occurrence xmlChar *occurrence = xmlGetNoNsProp(node, (const unsigned char*)"occurrence"); if (occurrence) { std::string occ((const char*)occurrence); if (occ == "*") r->occurrence = -1; else { char *end; r->occurrence = strtol(occ.c_str(), &end, 10); } xmlFree(occurrence); } //Get value xmlChar *value = xmlNodeGetContent(node); if (value) { r->value = std::string((const char*)value); xmlFree(value); } return 0; }
int main() { int gen = 1; int x = 0; int y; int width = 0; int height = 0; int born = 0; int died = 0; printf("Enter the number of generations: "); scanf("%d", &gen); while (gen < 1) { printf("Please enter a valid generation number: "); scanf("%d", &gen); } printf("Enter the dimensions of the game board: "); scanf("%d %d", &width, &height); if (width > 80 || height > 100) { printf("Please enter new dimensions: "); scanf("%d %d", &width, &height); } //first create array char board[width][height]; //array created with given dimensions //populate gameboard with '-' using loop makeboard((char *)board, width, height); //Loop to grab coordinates while (x != -1) { printf("\nEnter coordinates: "); //can't be bigger than height and width of the board scanf("%d %d", &x, &y); //easier to implement and read when adding * in the main method if (x <= width && y <= height) board[x-1][y-1] = '*'; else printf("Out of bounds"); } printf("Initial State\n"); printboard((char *)board, width, height); //PART TWO - Life and Death //first find cells and use occ if they are occupied. //died counter goes up if parameters are matched //born goes up when every cell is analyzed and occ is 3 for any one of them int genIterator; for (genIterator = 1; genIterator <= gen; genIterator++) { printf("\nGeneration #%d", genIterator); for (x = 0; x < width; x++) { for (y = 0; y < height; y++ ) { if ((board[x][y] == '*') && (2 <= (occ((char*)board, width, height, x, y))) && ((occ((char*)board, width, height, x, y)) <= 3)) { //it gets to live } if ((board[x][y] == '-') && ((occ((char*)board, width, height, x, y)) == 3)) { board[x][y] = '^'; //an organism is marked as born born++; } if ((board[x][y] == '*') && ((2 > (occ((char*)board, width, height, x, y))) || ((occ((char*)board, width, height, x, y)) >= 4))) { //if occ is less than 2 board[x][y] = 'x'; //x,y is now marked for death died++; } } } //go back through and replace the dead and the born with their appropriate symbols for (y = 0; y < height; y++ ) { for (x = 0; x < width; x++) { if (board[x][y] == 'x') { board[x][y] = '-'; } else if(board[x][y] == '^') { board[x][y] = '*'; } } } printf("\nNumber born = %d", born); printf(" Number died = %d \n", died); printboard((char *)board, width, height); died = 0; born = 0; } return 0; }
void ovm_q_atan2(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), 0.0); } else { mpfr_set_ui(orr(r), 0, thr_rnd); goto mpr; } break; case t_word: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), r->v.w); } else { mpfr_set_si(orr(r), r->v.w, thr_rnd); goto mpr; } break; case t_float: l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), mpz_get_d(ozr(r))); } else { mpfr_set_z(orr(r), ozr(r), thr_rnd); goto mpr; } break; case t_rat: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), rat_get_d(r->v.r)); } else { mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpq: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), mpq_get_d(oqr(r))); } else { mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpr: mpr: mpfr_set_q(orr(l), oqr(l), thr_rnd); l->t = t_mpr; mpfr_atan2(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: cdd: l->t = t_cdd; real(l->v.dd) = mpq_get_d(oqr(l)); imag(l->v.dd) = 0.0; l->v.dd = catan(l->v.dd / r->v.dd); check_cdd(l); break; case t_cqq: if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; } mpc_set_q_q(occ(r), oqr(r), oqi(r), thr_rndc); case t_mpc: l->t = t_mpc; mpc_set_q(occ(l), oqr(l), thr_rndc); mpc_div(occ(l), occ(l), occ(r), thr_rndc); mpc_atan(occ(l), occ(l), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
uint8_t Calendar::listNext(uint8_t number, Event::Occurrence into[], const DateTime & dt) { uint8_t ev=0; uint8_t addedIdx = 0; { Chronos::DateTime farFuture(Chronos::DateTime::endOfTime()); Event::Occurrence dummy(EVENTID_NOTSET, farFuture, farFuture); for (uint8_t i=0; i<number;i++) into[i]=dummy; } while (ev < num_events) { Chronos::Event * evt = this->eventSlot(ev++); if (NULL == evt) continue; if (! evt->hasNext(dt)) { continue; } uint8_t maxNumToAdd = evt->isRecurring() ? number : 1; bool didInsert = false; DateTime recStartDt(dt); for (uint8_t addNum=0; addNum<maxNumToAdd; addNum++ ) { Event::Occurrence occ(evt->nextOccurrence(recStartDt)); for (int16_t i=number; i>=0; i--) { if (occ.start < into[i].start) { // ok, this event bumps one from our return array, // we place it at the end of the array, as we know // that guy'll be bumped out into[number-1] = occ; // now we have a mostly-sorted array where all elements // are <= to the ones to their right, except (possibly) // for our new guy, e.g. // [1,1,2,3,4,4 ... 20, NEWGUY] // what we need is to move him left until we can't anymore Chronos::Sort::leftSortLastElement(into, number); // Chronos::Sort::bubble(into, number); didInsert = true; break; } } if (! didInsert) { // all future occurrences won't fit either break; } recStartDt = occ.start + Chronos::Span::Seconds(1); } } while (addedIdx < number) { if (into[addedIdx].id == EVENTID_NOTSET) { break; } addedIdx++; } return addedIdx; }
void ovm_q_pow(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: if (!cfg_float_format) { l->t = t_float; l->v.d = 1.0; } else { l->t = t_mpr; mpfr_set_ui(orr(l), 1, thr_rnd); } break; case t_word: if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), r->v.w); } else { mpfr_set_si(orr(r), r->v.w, thr_rnd); goto mpr; } break; case t_float: if (mpq_sgn(oqr(l)) < 0 && finite(r->v.d) && rint(r->v.d) != r->v.d) { real(r->v.dd) = r->v.d; imag(r->v.dd) = 0.0; goto cdd; } l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), mpz_get_d(ozr(r))); } else { mpfr_set_z(orr(r), ozr(r), thr_rnd); goto mpr; } break; case t_rat: if (mpq_sgn(oqr(l)) < 0) { if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; } mpc_set_q(occ(r), oqr(r), thr_rndc); goto mpc; } else { if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), rat_get_d(r->v.r)); } else { mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } } break; case t_mpq: if (mpq_sgn(oqr(r)) < 0) { if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; } mpc_set_q(occ(r), oqr(r), thr_rndc); goto mpc; } else { if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), mpq_get_d(oqr(r))); } else { mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } } break; case t_mpr: if (mpq_sgn(oqr(l)) < 0 && mpfr_number_p(orr(r)) && !mpfr_integer_p(orr(r))) { mpc_set_q(occ(r), oqr(r), thr_rndc); goto mpc; } mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_pow(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: cdd: l->t = t_cdd; real(l->v.dd) = mpq_get_d(oqr(l)); imag(l->v.dd) = 0.0; l->v.dd = cpow(l->v.dd, r->v.dd); check_cdd(l); break; case t_cqq: if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; } mpc_set_q_q(occ(r), oqr(r), oqi(r), thr_rndc); case t_mpc: mpc: l->t = t_mpc; mpc_set_q(occ(l), oqr(l), thr_rndc); mpc_pow(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }