static int get_decimal_str(ipint_t *s, char **str, char **start){ int i; int nchars=((s->used-1)*DATA_WIDTH+get_num_bits(s,s->used-1))/3.32192809488736234787031+3; // log2(s)/log2(10) ipint_t q; ipint_t r; ipint_t d; ipint_t end; ipint_t temp; ipdata_t di=10,endi=9; char *ptr; ptr=malloc(nchars); if(ptr==NULL) return IPECAC_ERROR; ipecac_init(&temp,0); ipecac_init(&q,0); ipecac_init(&r,0); // Can we fake this? ipecac_clone(&temp,s); d.sign=SIGN_POS; d.allocated=1; d.data=&di; d.used=1; end.sign=SIGN_POS; end.allocated=1; end.data=&endi; end.used=1; i=nchars; ptr[--i]=0; do{ ipecac_div(&q,&r,&temp,&d); ipecac_clone(&temp,&q); ptr[--i]='0'+r.data[0]; }while(ipecac_cmp(&q,&end)>0); ptr[--i]='0'+q.data[0]; *start=ptr+i; while(i>0)ptr[--i]='0'; *str=ptr; return IPECAC_SUCCESS; }
void udoc_relation::expand_column_vector(unsigned_vector& v, const udoc_relation* other) const { unsigned_vector orig; orig.swap(v); for (unsigned i = 0; i < orig.size(); ++i) { unsigned col, limit; if (orig[i] < get_num_cols()) { col = column_idx(orig[i]); limit = col + column_num_bits(orig[i]); } else { unsigned idx = orig[i] - get_num_cols(); col = get_num_bits() + other->column_idx(idx); limit = col + other->column_num_bits(idx); } for (; col < limit; ++col) { v.push_back(col); } } }
int num_transitions_to_change_max(int from, int to) { int to_switch_off = from & (~to); int to_switch_on = to & (~from); return get_num_bits(to_switch_off) + get_num_bits(to_switch_on); }
int num_transitions_to_change_sam(int from, int to) { return get_num_bits(from) + get_num_bits(to); }