/* * compute_stringnum: compute number of valid strings in expansion. */ int compute_stringnum(int orbs, int elecs, int ndocc, int nactv, int xlvl) { int num = 0; /* Number of strings */ int min_docc_elecs = 0; int max_docc_elecs = 0; int max_actv_elecs = 0; int min_actv_elecs = 0; int vorbs = 0; int count = 0; int i, j, k; vorbs = orbs - ndocc - nactv; min_docc_elecs = ndocc - int_min(ndocc, xlvl); max_docc_elecs = ndocc; min_actv_elecs = (elecs - ndocc) - int_min((elecs - ndocc), xlvl); //max_actv_elecs = int_min(((elecs - ndocc) + xlvl), nactv); max_actv_elecs = int_min(int_min(ndocc, xlvl) + (elecs - ndocc), nactv); printf(" Min DOCC elecs: %d, Min ACTV elecs: %d, Max ACTV elecs: %d\n", min_docc_elecs, min_actv_elecs, max_actv_elecs); /* Loop over holes in DOCC space */ for (i = min_docc_elecs; i <= max_docc_elecs; i++) { /* Loop over ACTV space */ for (j = min_actv_elecs; j <= max_actv_elecs; j++) { /* Loop over virtual space */ for (k = 0; k <= int_min(vorbs, xlvl); k++) { num = num + string_number(i, j, k, ndocc, nactv, orbs, elecs); } } } return num; }
/** * Updates the components characteristics of the image from the coding parameters. * * @param p_image_header the image header to update. * @param p_cp the coding parameters from which to update the image. */ void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp_v2 * p_cp) { OPJ_UINT32 i, l_width, l_height; OPJ_INT32 l_x0, l_y0, l_x1, l_y1; OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1; opj_image_comp_t* l_img_comp = NULL; l_x0 = int_max(p_cp->tx0 , p_image_header->x0); l_y0 = int_max(p_cp->ty0 , p_image_header->y0); l_x1 = int_min(p_cp->tx0 + p_cp->tw * p_cp->tdx, p_image_header->x1); l_y1 = int_min(p_cp->ty0 + p_cp->th * p_cp->tdy, p_image_header->y1); l_img_comp = p_image_header->comps; for (i = 0; i < p_image_header->numcomps; ++i) { l_comp_x0 = int_ceildiv(l_x0, l_img_comp->dx); l_comp_y0 = int_ceildiv(l_y0, l_img_comp->dy); l_comp_x1 = int_ceildiv(l_x1, l_img_comp->dx); l_comp_y1 = int_ceildiv(l_y1, l_img_comp->dy); l_width = int_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor); l_height = int_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor); l_img_comp->w = l_width; l_img_comp->h = l_height; l_img_comp->x0 = l_comp_x0/*l_x0*/; l_img_comp->y0 = l_comp_y0/*l_y0*/; ++l_img_comp; } }
void group_layouter(struct dialog_data *dlg_data) { struct terminal *term = dlg_data->win->term; int w = dialog_max_width(term); int rw; int y = 0; int n = dlg_data->number_of_widgets - 2; #ifdef CONFIG_UTF8 if (term->utf8_cp) rw = int_min(w, utf8_ptr2cells(dlg_data->dlg->title, NULL)); else #endif /* CONFIG_UTF8 */ rw = int_min(w, strlen(dlg_data->dlg->title)); dlg_format_group(dlg_data, dlg_data->widgets_data, n, 0, &y, w, &rw, 1); y++; dlg_format_buttons(dlg_data, dlg_data->widgets_data + n, 2, 0, &y, w, &rw, ALIGN_CENTER, 1); w = rw; draw_dialog(dlg_data, w, y); y = dlg_data->box.y + DIALOG_TB + 1; dlg_format_group(dlg_data, dlg_data->widgets_data, n, dlg_data->box.x + DIALOG_LB, &y, w, NULL, 0); y++; dlg_format_buttons(dlg_data, dlg_data->widgets_data + n, 2, dlg_data->box.x + DIALOG_LB, &y, w, &rw, ALIGN_CENTER, 0); }
int j2kTierOne::initCtxSC(int ctx) { int hc = int_min(((ctx & (T1_SIG_E | T1_SGN_E)) == T1_SIG_E) + ((ctx & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), 1) - int_min(((ctx & (T1_SIG_E | T1_SGN_E)) == (T1_SIG_E | T1_SGN_E)) + ((ctx & (T1_SIG_W | T1_SGN_W)) ==(T1_SIG_W | T1_SGN_W)), 1);//水平方向,最大为1 int vc = int_min(((ctx & (T1_SIG_N | T1_SGN_N)) == T1_SIG_N) + ((ctx & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),1) - int_min(((ctx & (T1_SIG_N | T1_SGN_N)) == (T1_SIG_N | T1_SGN_N)) +((ctx & (T1_SIG_S | T1_SGN_S)) == (T1_SIG_S | T1_SGN_S)), 1);//垂直方向,最大为1 //以上此举是为了用一定的数值去表达 if(hc<0) { hc=-hc; vc=-vc; } int n=0; if(!hc) { if(vc==-1) n=1; else if(!vc) n=0; else n=1; } else if(hc==1) { if(vc==-1) n=2; else if(!vc) n=3; else n=4; } return T1_CTXNO_SC+n; }
/// <summary> /// Get next packet in resolution-precinct-component-layer order. /// </summary> int pi_next_rpcl(pi_iterator_t *pi) { pi_comp_t *comp; pi_resolution_t *res; if (!pi->first) { goto skip; } else { int compno, resno; pi->first=0; pi->dx=0; pi->dy=0; for (compno=0; compno<pi->numcomps; compno++) { comp=&pi->comps[compno]; for (resno=0; resno<comp->numresolutions; resno++) { int dx, dy; res=&comp->resolutions[resno]; dx=comp->dx*(1<<(res->pdx+comp->numresolutions-1-resno)); dy=comp->dy*(1<<(res->pdy+comp->numresolutions-1-resno)); pi->dx=!pi->dx?dx:int_min(pi->dx, dx); pi->dy=!pi->dy?dy:int_min(pi->dy, dy); } } } for (pi->resno=pi->poc.resno0; pi->resno<pi->poc.resno1; pi->resno++) { for (pi->y=pi->ty0; pi->y<pi->ty1; pi->y+=pi->dy-(pi->y%pi->dy)) { for (pi->x=pi->tx0; pi->x<pi->tx1; pi->x+=pi->dx-(pi->x%pi->dx)) { for (pi->compno=pi->poc.compno0; pi->compno<pi->poc.compno1; pi->compno++) { int levelno; int trx0, try0; int rpx, rpy; int prci, prcj; comp=&pi->comps[pi->compno]; if (pi->resno>=comp->numresolutions) { continue; } res=&comp->resolutions[pi->resno]; levelno=comp->numresolutions-1-pi->resno; trx0=int_ceildiv(pi->tx0, comp->dx<<levelno); try0=int_ceildiv(pi->ty0, comp->dy<<levelno); rpx=res->pdx+levelno; rpy=res->pdy+levelno; if (!(pi->x%(comp->dx<<rpx)==0||(pi->x==pi->tx0&&(trx0<<levelno)%(1<<rpx)))) { continue; } if (!(pi->y%(comp->dy<<rpy)==0||(pi->y==pi->ty0&&(try0<<levelno)%(1<<rpx)))) { continue; } prci=int_floordivpow2(int_ceildiv(pi->x, comp->dx<<levelno), res->pdx)-int_floordivpow2(trx0, res->pdx); prcj=int_floordivpow2(int_ceildiv(pi->y, comp->dy<<levelno), res->pdy)-int_floordivpow2(try0, res->pdy); pi->precno=prci+prcj*res->pw; for (pi->layno=0; pi->layno<pi->poc.layno1; pi->layno++) { return 1; skip: ; } } } } } return 0; }
static void draw_file_download(struct listbox_item *item, struct listbox_context *context, int x, int y, int width) { struct file_download *file_download = item->udata; struct download *download = &file_download->download; unsigned char *stylename; struct color_pair *color; unsigned char *text; int length; int trimmedlen; int meter = DOWNLOAD_METER_WIDTH; /* We have nothing to work with */ if (width < 4) return; stylename = (item == context->box->sel) ? "menu.selected" : ((item->marked) ? "menu.marked" : "menu.normal"); color = get_bfu_color(context->term, stylename); text = get_file_download_text(item, context->term); if (!text) return; length = strlen(text); /* Show atleast the required percentage of the URI */ if (length * DOWNLOAD_URI_PERCENTAGE / 100 < width - meter - 4) { trimmedlen = int_min(length, width - meter - 4); } else { trimmedlen = int_min(length, width - 3); } draw_text(context->term, x, y, text, trimmedlen, 0, color); if (trimmedlen < length) { draw_text(context->term, x + trimmedlen, y, "...", 3, 0, color); trimmedlen += 3; } mem_free(text); if (!download->progress || download->progress->size < 0 || !is_in_state(download->state, S_TRANS) || !has_progress(download->progress)) { /* TODO: Show trimmed error message. */ return; } if (!dialog_has_refresh(context->dlg_data)) refresh_dialog(context->dlg_data, refresh_file_download, NULL); if (trimmedlen + meter >= width) return; x += width - meter; draw_progress_bar(download->progress, context->term, x, y, meter, NULL, NULL); }
void draw_progress_bar(struct progress *progress, struct terminal *term, int x, int y, int width, unsigned char *text, struct color_pair *meter_color) { /* Note : values > 100% are theorically possible and were seen. */ int percent = 0; struct box barprogress; if (progress->size > 0) percent = (int) ((longlong) 100 * progress->pos / progress->size); /* Draw the progress meter part "[### ]" */ if (!text && width > 2) { width -= 2; draw_text(term, x++, y, "[", 1, 0, NULL); draw_text(term, x + width, y, "]", 1, 0, NULL); } if (!meter_color) meter_color = get_bfu_color(term, "dialog.meter"); set_box(&barprogress, x, y, int_min(width * percent / 100, width), 1); draw_box(term, &barprogress, ' ', 0, meter_color); /* On error, will print '?' only, should not occur. */ if (text) { width = int_min(width, strlen(text)); } else if (width > 1) { static unsigned char s[] = "????"; /* Reduce or enlarge at will. */ unsigned int slen = 0; int max = int_min(sizeof(s), width) - 1; if (ulongcat(s, &slen, percent, max, 0)) { s[0] = '?'; slen = 1; } s[slen++] = '%'; /* Draw the percentage centered in the progress meter */ x += (1 + width - slen) / 2; assert(slen <= width); width = slen; text = s; } draw_text(term, x, y, text, width, 0, NULL); }
void group_layouter(struct dialog_data *dlg_data) { struct terminal *term = dlg_data->win->term; int w = dialog_max_width(term); int rw = int_min(w, strlen(dlg_data->dlg->title)); int y = 0; int n = dlg_data->number_of_widgets - 2; dlg_format_group(NULL, dlg_data->widgets_data, n, 0, &y, w, &rw); y++; dlg_format_buttons(NULL, dlg_data->widgets_data + n, 2, 0, &y, w, &rw, ALIGN_CENTER); w = rw; draw_dialog(dlg_data, w, y); y = dlg_data->box.y + DIALOG_TB + 1; dlg_format_group(term, dlg_data->widgets_data, n, dlg_data->box.x + DIALOG_LB, &y, w, NULL); y++; dlg_format_buttons(term, dlg_data->widgets_data + n, 2, dlg_data->box.x + DIALOG_LB, &y, w, &rw, ALIGN_CENTER); }
static int do_op_right(struct form_state *fs, struct line_info *line, int current, int utf8) { unsigned char *text, *end; int old_state; if (!utf8) { /* TODO: zle */ fs->state = int_min(fs->state + 1, strlen(fs->value)); return 0; } if (fs->state_cell) { fs->state_cell = 0; return 0; } text = fs->value + fs->state; end = strchr((const char *)text, '\0'); old_state = fs->state; utf8_to_unicode(&text, end); fs->state = text - fs->value; if (old_state != fs->state && line[current].split_next) { fs->state_cell = (fs->state == line[current].end) ? old_state:0; } else if (!line[current].split_next) { fs->state_cell = 0; } return 0; }
/* * stuck * sets out[i] to 0 where i in dat is a stuck value */ int stuck(signed char *out, const double *dat, size_t len, double reso, int num) { int i,j,k; int i_max; num=abs(num); if(num==0) num=10; int *tmp = malloc(sizeof(int) * (num-1)); for(i=0;i<(len - num + 1);i++) { i_max = int_min(i+num, len)-1; if(comp_res(dat[i], dat[i_max], reso)) { for(j=i;j<i_max;j++) { tmp[(i_max)-1-j] = comp_res(dat[j], dat[i_max], reso); } if(all(tmp, num-1)) { for(k=i;k<=i_max;k++) { out[k] = 0; } } } } free(tmp); return 0; }
void test_fx_fixed_limits_double(ostream& out) { out << "****************** limits fx_fixed<8, 5>_double\n"; sc_fixed<8, 5> zero_min("-0"); SHOW(zero_min); sc_fixed<8, 5> zero_plus("+0"); SHOW(zero_plus); sc_fixed<8, 5> zero(0); SHOW(zero); sc_fixed<8, 5> long_max(LONG_MAX); SHOW(long_max); sc_fixed<8, 5> long_min(LONG_MIN); SHOW(long_min); sc_fixed<8, 5> int_max(INT_MAX); SHOW(int_max); sc_fixed<8, 5> int_min(INT_MIN); SHOW(int_min); sc_fixed<8, 5> uint_max(UINT_MAX); SHOW(uint_max); sc_fixed<8, 5> ulong_max(ULONG_MAX); SHOW(ulong_max); sc_fixed<8, 5> double_min(DBL_MIN); SHOW(double_min); sc_fixed<8, 5> double_max(DBL_MAX); SHOW(double_max); sc_fixed<8, 5> float_min(FLT_MIN); SHOW(float_min); sc_fixed<8, 5> float_max(FLT_MAX); SHOW(float_max); // sc_fixed<8, 5> res; // SHOW_EXPS(double_min); // SHOW_EXPS(double_max); // SHOW_EXPS(float_min); // SHOW_EXPS(float_max); }
void test_fx_fix_limits_long(ostream& out) { out << "****************** limits fx_fix_long\n"; sc_fix zero_min("-0"); SHOW(zero_min); sc_fix zero_plus("+0"); SHOW(zero_plus); sc_fix zero(0); SHOW(zero); sc_fix long_max(LONG_MAX); SHOW(long_max); sc_fix long_min(LONG_MIN); SHOW(long_min); sc_fix int_max(INT_MAX); SHOW(int_max); sc_fix int_min(INT_MIN); SHOW(int_min); sc_fix uint_max(UINT_MAX); SHOW(uint_max); sc_fix ulong_max(ULONG_MAX); SHOW(ulong_max); sc_fix double_min(DBL_MIN); SHOW(double_min); sc_fix double_max(DBL_MAX); SHOW(double_max); sc_fix float_min(FLT_MIN); SHOW(float_min); sc_fix float_max(FLT_MAX); SHOW(float_max); // sc_fix res; // SHOW_EXPS(long_max); // SHOW_EXPS(long_min); // SHOW_EXPS(int_max); // SHOW_EXPS(int_min); // SHOW_EXPS(uint_max); // SHOW_EXPS(ulong_max); }
/* * generate_determinant_list: generate determinant list. */ void generate_determinant_list(struct eostring *pstrlist, int npstr, int aelec, struct eostring *qstrlist, int nqstr, int belec, struct eospace *peosp, int pegrps, struct eospace *qeosp, int qegrps, int ndocc, int nactv, int xlvl, int *dtrm_len) { int dcnt = 0; /* Determinant count */ int doccmin = 0; /* Minimum occupation for DOCC orbitals */ int virtmax = 0; /* Maximum occupation ofr VIRT orbitals */ FILE *fptr = NULL; int i, j; /* Set max/min occupation numbers of alpha + beta strings */ doccmin = 2 * (ndocc - int_min(ndocc, xlvl)); virtmax = xlvl; /* Open determinant file */ fptr = fopen("det.list","w"); /* Loop over p string groups */ for (i = 0; i < pegrps; i++) { /* Loop over q string groups */ for (j = 0; j < qegrps; j++) { if ((peosp[i].docc + qeosp[j].docc) < doccmin) continue; if ((peosp[i].virt + qeosp[j].virt) > virtmax) continue; write_determinant_strpairs(fptr, peosp[i].start, peosp[i].nstr, qeosp[j].start, qeosp[j].nstr, &dcnt, pstrlist, qstrlist); } } *dtrm_len = dcnt; return; }
/** A select_handler_T write_func for itrm_out.sock. This is called * when there is data in @c itrm->out.queue and it is possible to write * it to @c itrm->out.sock. When @c itrm->out.queue becomes empty, this * handler is temporarily removed. */ static void itrm_queue_write(struct itrm *itrm) { int written; int qlen = int_min(itrm->out.queue.len, 128); assertm(qlen, "event queue empty"); if_assert_failed return; written = safe_write(itrm->out.sock, itrm->out.queue.data, qlen); if (written <= 0) { if (written < 0) free_itrm(itrm); /* write error */ return; } itrm->out.queue.len -= written; if (itrm->out.queue.len == 0) { set_handlers(itrm->out.sock, get_handler(itrm->out.sock, SELECT_HANDLER_READ), NULL, get_handler(itrm->out.sock, SELECT_HANDLER_ERROR), get_handler(itrm->out.sock, SELECT_HANDLER_DATA)); } else { assert(itrm->out.queue.len > 0); memmove(itrm->out.queue.data, itrm->out.queue.data + written, itrm->out.queue.len); } }
void EightDirections::update(float dt) { if (max_speed == 0) return; bool on = false; int dir = get_joystick_direction(1); if (dir == 8) dir = instance->direction; else { on = true; dir *= 4; instance->set_direction(dir, false); } double mul = instance->frame->timer_mul; double change; if (on) change = get_accelerator(acceleration); else change = -get_accelerator(deceleration); set_speed(int_max(0, int_min(speed + change * mul, max_speed))); if (speed == 0) return; double add_x, add_y; get_dir(instance->direction, add_x, add_y); double m = get_pixels(speed) * mul; move(add_x * m, add_y * m); last_move = m; }
void test_fx_float_limits_zero(ostream& out) { cerr << "****************** limits fx_float_zero\n"; sc_fxval zero_min("-0"); SHOW(zero_min); sc_fxval zero_plus("+0"); SHOW(zero_plus); sc_fxval zero(0); SHOW(zero); sc_fxval nan("NaN"); SHOW(nan); sc_fxval inf_plus("+Inf"); SHOW(inf_plus); sc_fxval inf_min("-Inf"); SHOW(inf_min); sc_fxval inf("Inf"); SHOW(inf); sc_fxval long_max(LONG_MAX); SHOW(long_max); sc_fxval long_min(LONG_MIN); SHOW(long_min); sc_fxval int_max(INT_MAX); SHOW(int_max); sc_fxval int_min(INT_MIN); SHOW(int_min); sc_fxval uint_max(UINT_MAX); SHOW(uint_max); sc_fxval ulong_max(ULONG_MAX); SHOW(ulong_max); sc_fxval double_min(DBL_MIN); SHOW(double_min); sc_fxval double_max(DBL_MAX); SHOW(double_max); sc_fxval float_min(FLT_MIN); SHOW(float_min); sc_fxval float_max(FLT_MAX); SHOW(float_max); sc_fxval res; SHOW_EXPS(zero_min); SHOW_EXPS(zero_plus); SHOW_EXPS(zero); }
void Active::force_frame(int value) { if (loop_count == 0) return; int frame_count = direction_data->frame_count; forced_frame = int_max(0, int_min(value, frame_count - 1)); update_frame(); }
void array_rebound( array *arr, int new_length ) { void *new_mem = malloc( new_length * arr->size ); memcpy( new_mem, arr->mem, arr->size * int_min( new_length, arr->length ) ); free( arr->mem ); arr->mem = new_mem; arr->length = new_length; }
int j2kTierOne::initSPB(int ctx) { int hc = int_min(((ctx & (T1_SIG_E | T1_SGN_E)) == T1_SIG_E) + ((ctx & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),1) - int_min(((ctx & (T1_SIG_E | T1_SGN_E)) == (T1_SIG_E | T1_SGN_E)) + ((ctx & (T1_SIG_W | T1_SGN_W)) == (T1_SIG_W | T1_SGN_W)), 1); int vc = int_min(((ctx & (T1_SIG_N | T1_SGN_N)) == T1_SIG_N) + ((ctx & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), 1) - int_min(((ctx & (T1_SIG_N | T1_SGN_N)) == (T1_SIG_N | T1_SGN_N)) + ((ctx & (T1_SIG_S | T1_SGN_S)) == (T1_SIG_S | T1_SGN_S)), 1); int n=0; if(!hc&&!vc) n=0; else { n=!(hc>0||(!hc&&vc>0));//(hc>0)或者(hc=0且vc>0)时n=0 } return n; }
static void set_auth_user(struct auth_entry *entry, struct uri *uri) { int userlen = int_min(uri->userlen, AUTH_USER_MAXLEN - 1); if (userlen) memcpy(entry->user, uri->user, userlen); entry->user[userlen] = '\0'; }
static void set_auth_password(struct auth_entry *entry, struct uri *uri) { int passwordlen = int_min(uri->passwordlen, AUTH_PASSWORD_MAXLEN - 1); if (passwordlen) memcpy(entry->password, uri->password, passwordlen); entry->password[passwordlen] = '\0'; }
void draw_box(struct terminal *term, struct box *box, unsigned char data, int attr, struct color_pair *color) { struct screen_char *line, *pos, *end; int width, height; line = get_char(term, box->x, box->y); if (!line) return; height = int_min(box->height, term->height - box->y); width = int_min(box->width, term->width - box->x); if (height <= 0 || width <= 0) return; /* Compose off the ending screen position in the areas first line. */ end = &line[width - 1]; end->attr = attr; end->data = data; if (color) { set_term_color(end, color, 0, get_opt_int_tree(term->spec, (const unsigned char *)"colors", NULL)); } else { clear_screen_char_color(end); } /* Draw the first area line. */ for (pos = line; pos < end; pos++) { copy_screen_chars(pos, end, 1); } /* Now make @end point to the last line */ /* For the rest of the area use the first area line. */ pos = line; while (--height) { pos += term->width; copy_screen_chars(pos, line, width); } set_screen_dirty(term->screen, box->y, box->y + box->height); }
static S32 t1_init_ctxno_sc(S32 f) { S32 hc, vc, n; n = 0; hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), 1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == (T1_SIG_E | T1_SGN_E)) + ((f & (T1_SIG_W | T1_SGN_W)) == (T1_SIG_W | T1_SGN_W)), 1); vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), 1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == (T1_SIG_N | T1_SGN_N)) + ((f & (T1_SIG_S | T1_SGN_S)) == (T1_SIG_S | T1_SGN_S)), 1); if (hc < 0) { hc = -hc; vc = -vc; } if (!hc) { if (vc == -1) n = 1; else if (!vc) n = 0; else n = 1; } else if (hc == 1) { if (vc == -1) n = 2; else if (!vc) n = 3; else n = 4; } return (T1_CTXNO_SC + n); }
static S32 t1_init_spb(S32 f) { S32 hc, vc, n; hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), 1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == (T1_SIG_E | T1_SGN_E)) + ((f & (T1_SIG_W | T1_SGN_W)) == (T1_SIG_W | T1_SGN_W)), 1); vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), 1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == (T1_SIG_N | T1_SGN_N)) + ((f & (T1_SIG_S | T1_SGN_S)) == (T1_SIG_S | T1_SGN_S)), 1); if (!hc && !vc) n = 0; else n = (!(hc > 0 || (!hc && vc > 0))); return n; }
/*! Used by viewer to copy over a document. * When doing frame drawing @a x can be different than 0. */ void draw_line(struct terminal *term, int x, int y, int l, struct screen_char *line) { struct screen_char *screen_char = get_char(term, x, y); int size; assert(line); if_assert_failed return; if (!screen_char) return; size = int_min(l, term->width - x); if (size == 0) return; #ifdef CONFIG_UTF8 if (term->utf8_cp) { struct screen_char *sc; if (line[0].data == UCS_NO_CHAR && x == 0) { unicode_val_T data_save; sc = line; data_save = sc->data; sc->data = UCS_ORPHAN_CELL; copy_screen_chars(screen_char, line, 1); sc->data = data_save; size--; line++; screen_char++; } /* Instead of displaying double-width character at last column * display only UCS_ORPHAN_CELL. */ if (size - 1 > 0 && unicode_to_cell(line[size - 1].data) == 2) { unicode_val_T data_save; sc = &line[size - 1]; data_save = sc->data; sc->data = UCS_ORPHAN_CELL; copy_screen_chars(screen_char, line, size); sc->data = data_save; } else { copy_screen_chars(screen_char, line, size); } } else #endif copy_screen_chars(screen_char, line, size); set_screen_dirty(term->screen, y, y); }
void PinballMovement::update(float dt) { if (stopped) return; y_speed += gravity / 10.0f; float m = instance->frame->timer_mul; float angle = get_pinball_angle(x_speed, y_speed); float dist = get_length(x_speed, y_speed); float decel = deceleration * m; dist -= decel / 50.0f; if (dist < 0.0f) dist = 0.0f; x_speed = dist * cos(angle); y_speed = -dist * sin(angle); speed = int_min(int(dist), 100); instance->set_direction((angle * 32.0f) / (2.0 * CHOW_PI), false); move((x_speed * m) / 10.0f, (y_speed * m) / 10.0f); }
/* * generate_determinant_list_rtnlist: generate determinant list, returning * the list. */ void generate_determinant_list_rtnlist(struct eostring *pstrlist, int npstr, int aelec, struct eostring *qstrlist, int nqstr, int belec, struct eospace *peosp, int pegrps, struct eospace *qeosp, int qegrps, int ndocc, int nactv, int xlvl, int dtrm_len, struct det *dtlist) { int dcnt = 0; /* Determinant count */ int doccmin = 0; /* Minimum occupation for DOCC orbitals */ int virtmax = 0; /* Maximum occupation ofr VIRT orbitals */ int cflag = 0; /* CAS flag */ int i, j; /* Set max/min occupation numbers of alpha + beta strings */ doccmin = 2 * (ndocc - int_min(ndocc, xlvl)); virtmax = xlvl; /* Loop over p string groups */ for (i = 0; i < pegrps; i++) { /* Loop over q string groups */ for (j = 0; j < qegrps; j++) { if ((peosp[i].docc + qeosp[j].docc) < doccmin) continue; if ((peosp[i].virt + qeosp[j].virt) > virtmax) continue; if ((peosp[i].virt + qeosp[j].virt) == 0) { cflag = 1; } else { cflag = 0; } write_determinant_strpairs_dtlist(peosp[i].start, peosp[i].nstr, qeosp[j].start, qeosp[j].nstr, pstrlist, qstrlist, aelec, belec, ndocc, nactv, dtlist, &dcnt, cflag); } } return; }
bignum::operator int() const { bignum temp(*this); temp.roundToIndex(ONES_PLACE); temp.convertBase(10); bignum int_max(numeric_limits<int>::max()); bignum int_min(numeric_limits<int>::min()); if (temp > int_max || temp < int_min) throw error_handler(__FILE__, __LINE__, "attempted conversion failed: bignum is too large to be converted to an int"); int return_int = 0; for (int i = 0; i < digitRange; i++) { int power = (pow((double)10, i)); return_int += (power * digits[ONES_PLACE + i]); } return return_int; }
void set_cursor(struct terminal *term, int x, int y, int blockable) { assert(term && term->screen); if_assert_failed return; if (blockable && get_opt_bool_tree(term->spec, (const unsigned char *)"block_cursor", NULL)) { x = term->width - 1; y = term->height - 1; } if (term->screen->cx != x || term->screen->cy != y) { check_range(term, x, y); set_screen_dirty(term->screen, int_min(term->screen->cy, y), int_max(term->screen->cy, y)); term->screen->cx = x; term->screen->cy = y; } }
static void signal_handler(void) { int64_t nanos = read_nanos(CLOCK_MONOTONIC); int current = current_buffer; int pos = bufpos[current]; if (pos > BUFSIZE - 1024) { fprintf(stderr, "%lld exceeded bufsize!\n", (long long)nanos); return; } long long diff = (long long)(nanos - target_nanos); int srv = snprintf(buffers[current] + pos, BUFSIZE - pos, "%.9f %lld\n", read_nanos(CLOCK_REALTIME) * (double)1E-9, diff); bufpos[current] = int_min(pos + srv, BUFSIZE); target_nanos += 1000000000LL; }