static char * double_to_str(double d, int decimal, char *buf, bool force_dot, bool suppress_zeros) { /* support really big numbers with %f? */ char tmpbuf[BUF_SIZE]; char *pre, *post, *c; long predot, postdot, sub, i; /* get pre and post dot sections as integers */ if (d < 0) d = -d; if (decimal > 0) predot = (long)d; else predot = double2int(d); sub = 1; for (i=0; i<decimal; i++) sub *= 10; postdot = double2int((d - (long)d) * (double)sub); if (postdot == sub) { /* we had a .9* that rounded up! */ postdot = 0; predot++; } pre = ulong_to_str((ulong)predot, 10, tmpbuf, 1, false); for (i=0, c = pre; *c; c++) buf[i++] = *c; if (force_dot || !(decimal == 0 || (suppress_zeros && postdot == 0))) { buf[i++] = '.'; post = ulong_to_str((ulong)postdot, 10, tmpbuf, decimal, false); for (c = post; *c; c++) buf[i++] = *c; /* remove trailing zeros */ if (suppress_zeros) { while (buf[i-1] == '0') i--; } } buf[i] = '\0'; ASSERT(i<BUF_SIZE); /* make sure don't overflow buffer */ return buf; }
void DoubleSpanSlider::update(double min, double max) { apex_assert_hard(step_ != 0.0); int mini = double2int(min, min); int maxi = double2int(max, min); if (minimum() != mini || maximum() != maxi) { double low = int2double(lowerValue()); double up = int2double(upperValue()); apex_assert_hard(int2double(maxi, min) == max); apex_assert_hard(int2double(mini, min) == min); min_ = min; max_ = max; QxtSpanSlider::setRange(mini, maxi); setLowerValue(double2int(low)); setUpperValue(double2int(up)); } }
void HistogramProcessor::greyworld() { double meanR = 0, meanG = 0, meanB = 0; // computing mean for (int i = rect.top(); i <= rect.bottom(); ++i) { QRgb *line = (QRgb*)image.scanLine(i); for (int j = rect.left(); j <= rect.right(); ++j) { meanR += qRed(line[j]); meanG += qGreen(line[j]); meanB += qBlue(line[j]); } } int s = rect.width()*rect.height(); meanR /= s, meanG /= s, meanB /= s; // making changes double avg = (meanR + meanG + meanB) / 3; for (int i = rect.top(); i <= rect.bottom(); ++i) { QRgb *line = (QRgb*)image.scanLine(i); for (int j = rect.left(); j <= rect.right(); ++j) { double r = qRed(line[j]), g = qGreen(line[j]), b = qBlue(line[j]); line[j] = qRgb(double2int(r*avg/meanR), double2int(g*avg/meanG), double2int(b*avg/meanB)); } } }
int aleat_int (int inicio, int fin) { /* ---------------------------------------------- *\ |* Función que genera un entero aleatório *| |* comprendido entre 'inicio' y 'fin' ambos *| |* incluidos *| |* ---------------------------------------------- *| |* Parámetro inicio: inicio del itervalo de *| |* selección *| |* Parámetro fin: fin del intervalo de selección *| |* ---------------------------------------------- *| |* Retorna el número entero generado *| \* ---------------------------------------------- */ return (inicio + double2int ((double) (fin - inicio) * (random () / (double) RAND_MAX))); }
UINT8 CProductSaleWin::PlusProc(void) { UINT8 ret; double ii; char *content; INT32 dotNum = 0;//小数位数 content = (char*)(m_pInput2->m_contentBuf); ret=is_Money(content); if (ret != SUCCESS) { return(ErrMsgBox(ret)); } ii = atof(content); DBG_PRINT(("ii= %lf",ii)); if(((UINT64)double2int(ii*GOODS_NUM_EXTENSION)) >= MAX_MONEY) { return (ErrMsgBox(ILLEGAL_AMOUNT)); } dotNum = CheckFloatBit(ii); DBG_PRINT(("dotNum= %d",dotNum)); if (dotNum>3) { DBG_PRINT(("--------ii = %f--------", ii)); DBG_PRINT(("--------dotNum = %d--------", dotNum)); CaMsgBox::ShowMsg("小数位数不超过三位"); return FAILURE; } m_pInput2->Clear(); ret = pSaleData->Plus(ii); if (ret != SUCCESS) { return(ErrMsgBox(ret)); } ReFresh(); return SUCCESS; }
void createWaterDrop(int x, int y, int size, int splashStrength, int *where, int xsize, int ysize) { int i,j, square_x, square_y, square_size; //where += (x-size)+xsize*(y-size); for (j=y-size; j<= y+size; ++j) { for (i=x-size; i <= x+size; ++i) { // make sure we're in bounds if (i < 0 || i >= xsize || j < 0 || j >= ysize) continue; // see if the point at (x,y) is within the circle of radius size square_x = (x-i)*(x-i); square_y = (y-j)*(y-j); square_size = size*size; if (square_x+square_y <= square_size) { where[(j*xsize)+i] += double2int((double)splashStrength*sqrt(square_x+square_y)); //*where += double2int(((double)splashStrength*sqrt(square_x+square_y))); } //++where; } //where+=xsize; } }
UINT8 SimpleMakeNormalInv(SaleData &tmpSaleData,string &strErr) { UINT8 ret; CInvDet *invDet = NULL; CInvHead invHead; tmpSaleData.m_smallInvInfo = &invHead; UINT32 nCurDate = TDateTime::CurrentDateTime().FormatInt(YYYYMMDD); UINT32 nCurTime = TDateTime::CurrentDateTime().FormatInt(HHMMSS); INT64 tmpDJ=0; INT64 moneyTaxSum=0; //组装正票 //组装发票头 //tmpSaleData.m_smallInvInfo->m_fphm = g_globalArg->m_curInvVol->m_ieno + 1 - // g_globalArg->m_curInvVol->m_remain; /**< 发票号码 */ ret = SALE_GetCurInv(g_globalArg->m_curInvVol,strErr); DBG_PRINT(("strErr= %s",strErr.c_str())); if (ret ==FAILURE) { DBG_PRINT(("获取当前发票号码错误:%s",strErr.c_str())); return ret; } tmpSaleData.m_smallInvInfo->m_fphm = g_globalArg->m_curInvVol->m_curInvNo; tmpSaleData.m_smallInvInfo->m_fpdm = g_globalArg->m_curInvVol->m_code; /**< 发票代码简称 */ tmpSaleData.m_smallInvInfo->m_kplx = NORMAL_INV; //开票类型 tmpSaleData.m_smallInvInfo->m_yfphm = 0; //原发票号码 tmpSaleData.m_smallInvInfo->m_yfpdm = ""; //原发票号码 tmpSaleData.m_smallInvInfo->m_fplb = atoi(g_globalArg->m_invKind->m_pzCode.c_str()); //发票种类 tmpSaleData.m_smallInvInfo->m_fkdw = "个人"; //付款人名称 tmpSaleData.m_smallInvInfo->m_fkdwsh = "012345678901234"; tmpSaleData.m_smallInvInfo->m_sky = g_globalArg->m_operator->m_name; //操作员名称 // tmpSaleData.m_smallInvInfo->m_opId = g_globalArg->m_operator->m_opId; //操作员id // tmpSaleData.m_smallInvInfo->m_uID = 0; //纳税户名称ID号 // tmpSaleData.m_smallInvInfo->m_ptype = 0; //付款方式 tmpSaleData.m_smallInvInfo->m_sphsl = 3;//当前发票总商品行加1 tmpSaleData.m_smallInvInfo->m_kphjje = (INT64)(3.00 * SUM_EXTENSION);//当前发票总金额 tmpSaleData.m_smallInvInfo->m_backup1 = ""; //备用字段1 // tmpSaleData.m_smallInvInfo->m_backup2 = ""; //备用字段2 // tmpSaleData.m_smallInvInfo->m_backup3 = ""; //备用字段3 //发票明细 for(UINT8 i = 1; i<4; i++) { // invDet = new CInvDet; invDet = invDet->GetNewInvDet();//从静态数组获取一个可用的CInvDet对象 DBG_ASSERT_EXIT((invDet != NULL), (" invDet == NULL!")); invDet->m_fpdm = tmpSaleData.m_smallInvInfo->m_fpdm; invDet->m_fphm = tmpSaleData.m_smallInvInfo->m_fphm; // invDet->m_sphxh = i; invDet->m_kprq = nCurDate; invDet->m_kpsj = nCurTime; invDet->m_kplx = NORMAL_INV; invDet->m_sky = g_globalArg->m_operator->m_name; invDet->m_spbm = "0000000000001"; invDet->m_sphxh = i; invDet->m_spmc = "测试商品1"; // invDet->m_taxId = 1; //非税控只允许税目1 invDet->m_spsl = 1.0; //保存四舍五入后的值 invDet->m_dotNum = 0; invDet->m_spdj = (double)1.00; invDet->m_spje = (INT64)(1.00*SUM_EXTENSION); invDet->m_sl = 0.03; invDet->m_spse=tmpSaleData.CountTax(invDet->m_spje, (UINT32)(invDet->m_sl*SUM_EXTENSION)); //商品税额 invDet->m_je= invDet->m_spje - invDet->m_spse; //商品金额(不含税) invDet->m_spdw = "个"; //商品单位 tmpDJ = double2int(invDet->m_spdj*SUM_EXTENSION); DBG_PRINT(("tmpDJ==%lld ", tmpDJ)); tmpDJ -=tmpSaleData.CountTax(double2int(invDet->m_spdj*SUM_EXTENSION), (UINT32)(invDet->m_sl*SUM_EXTENSION)); DBG_PRINT(("tmpDJ==%lld ", tmpDJ)); invDet->m_dj= (double)(tmpDJ*1.0)/SUM_EXTENSION; //商品单价(不含税) invDet->m_je= invDet->m_spje-invDet->m_spse; //商品金额(不含税) moneyTaxSum += invDet->m_spse; invDet->m_property = DETAIL_GENERAL_GOODS; invDet->m_backup = ""; tmpSaleData.m_smallInvInfo->InsertNode(invDet); //插入节点 } //当前发票累计税额增加 tmpSaleData.m_smallInvInfo->m_kpse = moneyTaxSum; DBG_PRINT(("当前发票累计税额 tmpSaleData.m_smallInvInfo->m_kpse = %lld", tmpSaleData.m_smallInvInfo->m_kpse)); moneyTaxSum = 0; ret = tmpSaleData.MakeInvoiceHandle(PRINT, INV_ROLL_PROC); tmpSaleData.m_smallInvInfo->DelList(); tmpSaleData.m_smallInvInfo = NULL; if (ret != SUCCESS) { if (ret==DB_FULL) { DBG_RETURN(DB_FULL); } else if (ret==HAVE_ROLLED) { DBG_RETURN(HAVE_ROLLED); } else { DBG_RETURN(ret); } } DBG_RETURN(SUCCESS); }
INT32 CFpkj::XmlParse(XMLParse *parse, CInvHead *pInvInfo) { UINT8 i = 0; parse->LocateNodeByName(parse->m_RootElement, "body"); parse->m_parentElement[1] = parse->m_Child; parse->LocateNodeByName(parse->m_parentElement[1], "input"); parse->m_parentElement[2] = parse->m_Child; parse->LocateNodeByName(parse->m_parentElement[2], "jqbh"); m_ywxml_gy.m_jqbh = parse->GetText(); //税控收款机编号 DBG_PRINT(("m_ywxml_gy.m_jqbh == %s", m_ywxml_gy.m_jqbh.c_str())); pInvInfo->m_jqbh = m_ywxml_gy.m_jqbh; DBG_PRINT(("pInvInfo->m_jqbh == %s", pInvInfo->m_jqbh.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "zskl"); pInvInfo->m_zskl = parse->GetText(); //证书口令 DBG_PRINT(("pInvInfo->m_zskl == %s", pInvInfo->m_zskl.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "xhdwdm"); m_ywxml_gy.m_nsrsbh = parse->GetText(); DBG_PRINT(("m_ywxml_gy.nsrsbh == %s", m_ywxml_gy.m_nsrsbh.c_str())); pInvInfo->m_xfsh = parse->GetText(); DBG_PRINT(("pInvInfo->m_xfsh == %s", pInvInfo->m_xfsh.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "xhdwmc"); pInvInfo->m_xfmc = parse->GetText(); DBG_PRINT(("pInvInfo->m_xfmc == %s", pInvInfo->m_xfmc.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "sksbbh"); m_ywxml_gy.m_sksbbh = parse->GetText(); DBG_PRINT(("m_ywxml_gy.sksbbh == %s", m_ywxml_gy.m_sksbbh.c_str())); pInvInfo->m_sksbbh = m_ywxml_gy.m_sksbbh; DBG_PRINT(("pInvInfo->m_sksbbh == %s", pInvInfo->m_sksbbh.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "sksbkl"); m_ywxml_gy.m_sksbkl = parse->GetText(); DBG_PRINT(("m_ywxml_gy.sksbkl == %s", m_ywxml_gy.m_sksbkl.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "fplxdm"); m_ywxml_gy.m_fplxdm = parse->GetText(); pInvInfo->m_fplxdm = m_ywxml_gy.m_fplxdm; DBG_PRINT(("m_ywxml_gy.fplxdm == %s", m_ywxml_gy.m_fplxdm.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "kplx"); pInvInfo->m_kplx = (UINT8)atoi(parse->GetText().c_str()); DBG_PRINT(("pInvInfo->m_kplx == %u", pInvInfo->m_kplx)); // parse->LocateNodeByName(parse->m_parentElement[2], "hyfl"); // pInvInfo->m_hyfl = parse->GetText(); // DBG_PRINT(("hyfl== %s", pInvInfo->m_hyfl.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "ghdwdm"); pInvInfo->m_payerCode = parse->GetText(); CJSKMakeInvoice::FilterSpace(pInvInfo->m_payerCode); if(pInvInfo->m_payerCode == "") pInvInfo->m_payerCode = "000000000000000"; DBG_PRINT(("pInvInfo->m_payerCode == %s", pInvInfo->m_payerCode.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "ghdwmc"); pInvInfo->m_fkdw = parse->GetText(); CJSKMakeInvoice::FilterSpace(pInvInfo->m_fkdw); DBG_PRINT(("pInvInfo->m_fkdw == %s", pInvInfo->m_fkdw.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "sfxm"); parse->m_parentElement[3] = parse->m_Child; pInvInfo->m_sphsl = atoi(parse->GetAttr("count").c_str()); //解析XML后得到商品明细行数 DBG_PRINT(("pInvInfo->m_sphsl == %u", pInvInfo->m_sphsl)); CInvDet* pInvDet = NULL; for (i=0; i<pInvInfo->m_sphsl; i++) { pInvDet = pInvDet->GetNewInvDet(); //从静态数组获取一个可用的CInvDet对象 DBG_ASSERT_EXIT((pInvDet != NULL), (" pInvDet == NULL!")); pInvDet->m_sphxh = i+1; //得到group节点 parse->LocateNodeByName(parse->m_parentElement[3], "group", i); parse->m_parentElement[4] = parse->m_Child; parse->LocateNodeByName(parse->m_parentElement[4], "xm"); pInvDet->m_spmc = parse->GetText(); CJSKMakeInvoice::FilterSpace(pInvDet->m_spmc); DBG_PRINT(("pInvDet->m_spmc == %s", pInvDet->m_spmc.c_str())); parse->LocateNodeByName(parse->m_parentElement[4], "dj"); pInvDet->m_dj = atof(parse->GetText().c_str()); DBG_PRINT(("pInvDet->m_dj == %lf", pInvDet->m_dj)); parse->LocateNodeByName(parse->m_parentElement[4], "sl"); pInvDet->m_spsl = atof(parse->GetText().c_str()); DBG_PRINT(("pInvDet->m_spsl == %lf", pInvDet->m_spsl)); parse->LocateNodeByName(parse->m_parentElement[4], "je"); pInvDet->m_je =double2int(atof(parse->GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("pInvDet->m_je == %lld", pInvDet->m_je)); parse->LocateNodeByName(parse->m_parentElement[4], "zsl"); pInvDet->m_sl = (float)atof(parse->GetText().c_str()); DBG_PRINT(("pInvDet->m_sl == %f", pInvDet->m_sl)); parse->LocateNodeByName(parse->m_parentElement[4], "se"); DBG_PRINT(("pInvDet->m_spse == %s", parse->GetText().c_str())); pInvDet->m_spse = double2int(atof(parse->GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("pInvDet->m_spse == %lld", pInvDet->m_spse)); parse->LocateNodeByName(parse->m_parentElement[4], "hsdj"); pInvDet->m_spdj = atof(parse->GetText().c_str()); DBG_PRINT(("pInvDet->m_spdj == %lf", pInvDet->m_spdj)); parse->LocateNodeByName(parse->m_parentElement[4], "hsje"); pInvDet->m_spje = double2int(atof(parse->GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("pInvDet->m_spje == %lld", pInvDet->m_spje)); pInvInfo->InsertNode(pInvDet); pInvDet = NULL; } parse->LocateNodeByName(parse->m_parentElement[2], "hjje"); pInvInfo->m_kpje = double2int(atof(parse->GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("pInvInfo->m_kpje == %lld", pInvInfo->m_kpje)); parse->LocateNodeByName(parse->m_parentElement[2], "hjse"); DBG_PRINT(("pInvDet->m_spse == %s", parse->GetText().c_str())); pInvInfo->m_kpse = double2int(atof(parse->GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("pInvInfo->m_kpse == %lld", pInvInfo->m_kpse)); parse->LocateNodeByName(parse->m_parentElement[2], "jshj"); pInvInfo->m_kphjje = double2int(atof(parse->GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("pInvInfo->m_kphjje == %lld", pInvInfo->m_kphjje)); parse->LocateNodeByName(parse->m_parentElement[2], "bz"); pInvInfo->m_backup1 = parse->GetText(); CJSKMakeInvoice::FilterSpace(pInvInfo->m_backup1); DBG_PRINT(("pInvInfo->m_backup1 == %s", pInvInfo->m_backup1.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "skr"); pInvInfo->m_sky = parse->GetText(); CJSKMakeInvoice::FilterSpace(pInvInfo->m_sky); DBG_PRINT(("pInvInfo->m_sky == %s", pInvInfo->m_sky.c_str())); // parse->LocateNodeByName(parse->m_parentElement[2], "kpr"); // pInvInfo->m_sky = parse->GetText(); // DBG_PRINT(("pInvInfo->m_sky == %s", pInvInfo->m_sky.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "yfpdm"); pInvInfo->m_yfpdm = parse->GetText(); DBG_PRINT(("pInvInfo->m_yfpdm == %s", pInvInfo->m_yfpdm.c_str())); parse->LocateNodeByName(parse->m_parentElement[2], "yfphm"); pInvInfo->m_yfphm = atoi(parse->GetText().c_str()); DBG_PRINT(("pInvInfo->m_yfphm == %u", pInvInfo->m_yfphm)); return SUCCESS; }
map<unsigned int, map<unsigned int, double>*>* ItemBaseCF::calc_recommendation( map<unsigned int, map<unsigned int, double>*>* data_matrix, unsigned int n) { map<pair<unsigned int, unsigned int>, double> sim_matrix; map<unsigned int, map<unsigned int, double>*>* rc_matrix = new map< unsigned int, map<unsigned int, double>*>(); for (map<unsigned int, map<unsigned int, double>*>::const_iterator iter = data_matrix->begin(); iter != data_matrix->end(); iter++) { unsigned int target_obj = iter->first; map<unsigned int, double> totals; map<unsigned int, double> sim_sums; map<unsigned int, double>* prefs = data_matrix->at(target_obj); for (map<unsigned int, double>::const_iterator item_iter = prefs->begin(); item_iter != prefs->end(); item_iter++) { vector<unsigned int>* sim_items = m_sim_items->at(item_iter->first); for (vector<unsigned int>::const_iterator sim_item_iter = sim_items->begin(); sim_item_iter != sim_items->end(); sim_item_iter++) { //忽略已经评价过的商品 if (prefs->find(*sim_item_iter) != prefs->end()) continue; //取出相似度 pair<unsigned int, unsigned int> sim_matrix_index; if (item_iter->first > *sim_item_iter) { sim_matrix_index.first = *sim_item_iter; sim_matrix_index.second = item_iter->first; } else { sim_matrix_index.first = item_iter->first; sim_matrix_index.second = *sim_item_iter; } double sim = 0; map<pair<unsigned int, unsigned int>, double>::const_iterator sim_iter = m_sim_matrix.find(sim_matrix_index); if (sim_iter == m_sim_matrix.end()) { sim = m_similarity(m_trans_matrix, item_iter->first, *sim_item_iter); m_sim_matrix.insert( pair<pair<unsigned int, unsigned int>, double>( sim_matrix_index, sim)); } else { sim = sim_iter->second; } //相似度*评价值 if (totals.find(*sim_item_iter) == totals.end()) { totals.insert( pair<unsigned int, double>(*sim_item_iter, 0)); } totals[*sim_item_iter] += item_iter->second * sim; //相似度之和 if (sim_sums.find(*sim_item_iter) == sim_sums.end()) { sim_sums.insert( pair<unsigned int, double>(*sim_item_iter, 0)); } sim_sums[*sim_item_iter] += sim; } } //建立一个归一化的列表 unsigned int item_index[totals.size()]; double scores[totals.size()]; unsigned int i = 0; for (map<unsigned int, double>::const_iterator iter = totals.begin(); iter != totals.end() && i < totals.size(); iter++, i++) { item_index[i] = iter->first; scores[i] = double2int(totals[iter->first] / sim_sums[iter->first]); } //对列表进行降序排序 quicksort<double>(scores, totals.size(), false, false, item_index); //记录前n个该对象可能会感兴趣的项目以及可能的评价 map<unsigned int, map<unsigned int, double>*>::const_iterator rc_iter = rc_matrix->find(target_obj); map<unsigned int, double>* rc_prefs = NULL; if (rc_iter == rc_matrix->end()) { rc_prefs = new map<unsigned int, double>(); rc_matrix->insert( pair<unsigned int, map<unsigned int, double>*>(target_obj, rc_prefs)); } else { rc_prefs = rc_iter->second; } unsigned int top_n = 0; if (n == 0 || n > totals.size()) { top_n = totals.size(); } for (i = 0; i < top_n; i++) { rc_prefs->insert( pair<unsigned int, double>(item_index[i], scores[i])); } } return rc_matrix; }
vector<pair<unsigned int, double> >* ItemBaseCF::get_recommendations( map<unsigned int, map<unsigned int, double>*>* data_matrix, unsigned int target_obj, unsigned int n) { //检查参数合法性 if (data_matrix->find(target_obj) == data_matrix->end()) { printf("the target object is not in the data!\n"); return NULL; } map<unsigned int, double> totals; map<unsigned int, double> sim_sums; map<unsigned int, double>* prefs = data_matrix->at(target_obj); for (map<unsigned int, double>::const_iterator iter = prefs->begin(); iter != prefs->end(); iter++) { vector<unsigned int>* sim_items = m_sim_items->at(iter->first); for (vector<unsigned int>::const_iterator item_iter = sim_items->begin(); item_iter != sim_items->end(); item_iter++) { //忽略已经评价过的商品 if (prefs->find(*item_iter) != prefs->end()) continue; //取出相似度 pair<unsigned int, unsigned int> sim_matrix_index; if (iter->first > *item_iter) { sim_matrix_index.first = *item_iter; sim_matrix_index.second = iter->first; } else { sim_matrix_index.first = iter->first; sim_matrix_index.second = *item_iter; } double sim = 0; map<pair<unsigned int, unsigned int>, double>::const_iterator sim_iter = m_sim_matrix.find(sim_matrix_index); if (sim_iter == m_sim_matrix.end()) { sim = m_similarity(m_trans_matrix, iter->first, *item_iter); m_sim_matrix.insert( pair<pair<unsigned int, unsigned int>, double>( sim_matrix_index, sim)); } else { sim = sim_iter->second; } //相似度*评价值 if (totals.find(*item_iter) == totals.end()) { totals.insert(pair<unsigned int, double>(*item_iter, 0)); } totals[*item_iter] += iter->second * sim; //相似度之和 if (sim_sums.find(*item_iter) == sim_sums.end()) { sim_sums.insert(pair<unsigned int, double>(*item_iter, 0)); } sim_sums[*item_iter] += sim; } } //建立一个归一化的列表 unsigned int item_index[totals.size()]; double scores[totals.size()]; unsigned int i = 0; for (map<unsigned int, double>::const_iterator iter = totals.begin(); iter != totals.end() && i < totals.size(); iter++, i++) { item_index[i] = iter->first; scores[i] = double2int(totals[iter->first] / sim_sums[iter->first]); } //对列表进行降序排序 quicksort<double>(scores, totals.size(), false, false, item_index); //返回前n个该对象可能会感兴趣的项目以及可能的评价 vector<pair<unsigned int, double> >* top_k_scores = new vector< pair<unsigned int, double> >(); if (n == 0 || n > totals.size()) { n = totals.size(); } for (i = 0; i < n; i++) { top_k_scores->push_back( pair<unsigned int, double>(item_index[i], scores[i])); } return top_k_scores; }
INT32 CFpcx::XmlParse() { UINT8 i = 0; UINT8 j = 0; UINT8 fpzt = 0; //添加body节点 m_pXmlParse.LocateNodeByName(m_pXmlParse.m_RootElement, "body"); m_pXmlParse.m_parentElement[1] = m_pXmlParse.m_Child; m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[1], "output"); m_pXmlParse.m_parentElement[2] = m_pXmlParse.m_Child; m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[2], "returncode"); m_retInfo.m_retCode = m_pXmlParse.GetText(); DBG_PRINT(("returncode : %s", m_retInfo.m_retCode.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[2], "returnmsg"); m_retInfo.m_retMsg = m_pXmlParse.GetText(); DBG_PRINT(("returnmsg : %s", m_retInfo.m_retMsg.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[2], "fpxx"); m_pXmlParse.m_parentElement[3] = m_pXmlParse.m_Child; m_InvCOunt = atoi(m_pXmlParse.GetAttr("count").c_str()); for (i=0; i<m_InvCOunt; i++) { m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[3], "group", i); m_pXmlParse.m_parentElement[4] = m_pXmlParse.m_Child; m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "fpdm"); m_InvInfo.m_fpdm = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_fpdm : %s", m_InvInfo.m_fpdm.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "fphm"); m_InvInfo.m_fphm = atoi(m_pXmlParse.GetText().c_str()); DBG_PRINT(("m_InvInfo.m_fphm : %u", m_InvInfo.m_fphm)); //发票状态 m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "fpzt"); fpzt = atoi(m_pXmlParse.GetText().c_str()); switch(fpzt) { case 0: m_InvInfo.m_kplx = NORMAL_INV; break; case 1: m_InvInfo.m_kplx = RETURN_INV; break; case 2: m_InvInfo.m_kplx = WASTE_INV; break; case 3: m_InvInfo.m_kplx = WASTE_NOR; break; case 4: m_InvInfo.m_kplx = WASTE_RET; break; } m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "scbz"); m_InvInfo.m_scbz = (UINT8)atoi(m_pXmlParse.GetText().c_str()); DBG_PRINT(("m_InvInfo.m_scbz : %u", m_InvInfo.m_scbz)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "kprq"); m_InvInfo.m_kprq = atoi(m_pXmlParse.GetText().c_str()); DBG_PRINT(("m_InvInfo.m_kprq : %u", m_InvInfo.m_kprq)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "kpsj"); m_InvInfo.m_kpsj = atoi(m_pXmlParse.GetText().c_str()); DBG_PRINT(("m_InvInfo.m_kpsj : %u", m_InvInfo.m_kpsj)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "skm"); m_InvInfo.m_fwm = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_fwm : %s", m_InvInfo.m_fwm.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "sksbbh"); //税控设备编号 m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "skdwmc"); //收款单位名称 m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "xhdwdm"); //销货单位识别号 m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "xhdwmc"); //销货单位名称 //购货单位识别号 m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "ghdwdm"); m_InvInfo.m_fkdwsh = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_fkdwsh : %s",m_InvInfo.m_fkdwsh.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "ghdwmc"); m_InvInfo.m_fkdw = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_fkdw : %s",m_InvInfo.m_fkdw.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "sfxm"); m_pXmlParse.m_parentElement[5] = m_pXmlParse.m_Child; m_InvInfo.m_sphsl = atoi(m_pXmlParse.GetAttr("count").c_str()); DBG_PRINT(("m_InvInfo.m_sphsl : %u", m_InvInfo.m_sphsl)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "skr"); m_InvInfo.m_sky = m_pXmlParse.GetText();//中间件工程中,skr、kpr、zfr全用m_sky组装 DBG_PRINT(("m_InvInfo.m_sky : %s", m_InvInfo.m_sky.c_str())); CInvDet *pInvDet = NULL; for (j=0; j<m_InvInfo.m_sphsl; j++) { pInvDet = pInvDet->GetNewInvDet(); //从静态数组获取一个可用的CInvDet对象 DBG_ASSERT_EXIT((pInvDet != NULL), (" pInvDet == NULL!")); pInvDet->m_fpdm = m_InvInfo.m_fpdm; pInvDet->m_fphm = m_InvInfo.m_fphm; pInvDet->m_kprq = m_InvInfo.m_kprq; pInvDet->m_kpsj = m_InvInfo.m_kpsj; pInvDet->m_kplx = m_InvInfo.m_kplx; pInvDet->m_sky = m_InvInfo.m_sky; pInvDet->m_sphxh = j+1; m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[5], "group", j); m_pXmlParse.m_parentElement[6] = m_pXmlParse.m_Child; m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "xm");; pInvDet->m_spmc = m_pXmlParse.GetText(); DBG_PRINT(("pInvDet->m_spmc : %s", pInvDet->m_spmc.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "dj"); pInvDet->m_dj = atof(m_pXmlParse.GetText().c_str());//单价不含税 DBG_PRINT(("pInvDet->m_dj : %.3lf", pInvDet->m_dj)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "sl"); pInvDet->m_spsl = atof(m_pXmlParse.GetText().c_str());//数量 DBG_PRINT(("pInvDet->m_spdj : %.3lf", pInvDet->m_spsl)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "je"); pInvDet->m_je = double2int(atof(m_pXmlParse.GetText().c_str())*SUM_EXTENSION);//金额不含税 DBG_PRINT(("pInvDet->m_spje : %lld", pInvDet->m_je)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "zsl"); pInvDet->m_sl = atof(m_pXmlParse.GetText().c_str());//税率 DBG_PRINT(("pInvDet->m_sl : %.2lf", pInvDet->m_sl)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "se"); pInvDet->m_spse = double2int(atof(m_pXmlParse.GetText().c_str())*SUM_EXTENSION);//税额 DBG_PRINT(("pInvDet->m_spse : %lld", pInvDet->m_spse)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "hsdj"); pInvDet->m_spdj = atof(m_pXmlParse.GetText().c_str());//含税单价 DBG_PRINT(("pInvDet->m_spdj : %.3lf", pInvDet->m_spdj)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[6], "hsje"); pInvDet->m_spje = double2int(atof(m_pXmlParse.GetText().c_str())*SUM_EXTENSION);//含税金额 DBG_PRINT(("pInvDet->m_spje : %lld", pInvDet->m_spje)); m_InvInfo.InsertNode(pInvDet); pInvDet =NULL; } m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "hjje"); m_InvInfo.m_kpje = double2int(atof(m_pXmlParse.GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("m_InvInfo.m_kpje : %lld", m_InvInfo.m_kpje)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "hjse"); m_InvInfo.m_kpse = double2int(atof(m_pXmlParse.GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("m_InvInfo.m_kpse : %lld", m_InvInfo.m_kpse)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "jshj"); m_InvInfo.m_kphjje = double2int(atof(m_pXmlParse.GetText().c_str())*SUM_EXTENSION); DBG_PRINT(("m_InvInfo.m_kphjje : %lld", m_InvInfo.m_kphjje)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "bz"); m_InvInfo.m_backup1 = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_backup1 : %s", m_InvInfo.m_backup1.c_str())); // m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "kpr"); // m_InvInfo.m_sky = m_pXmlParse.GetText(); // DBG_PRINT(("m_InvInfo.m_sky : %s", m_InvInfo.m_sky.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "yfpdm"); m_InvInfo.m_yfpdm = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_yfpdm : %s", m_InvInfo.m_yfpdm.c_str())); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "yfphm"); m_InvInfo.m_yfphm = atoi(m_pXmlParse.GetText().c_str()); //作废日期 // m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "zfrq"); // memset(Buf, 0, sizeof(Buf)); // sprintf(Buf, "%u",m_InvInfo.zfrq); // m_pXmlParse.GetText(Buf); // DBG_PRINT(("buf : %s", Buf)); //作废人 // m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "zfr"); // m_pXmlParse.GetText(m_InvInfo.m_yfpdm); // DBG_PRINT(("m_InvInfo.m_yfpdm : %s", m_InvInfo.m_yfpdm.c_str())); //已开负数金额 // m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[4], "ykfsje"); // memset(Buf, 0, sizeof(Buf)); // sprintf(Buf, "%ld", m_InvInfo.m_kphjje); // m_pXmlParse.GetText(Buf); // DBG_PRINT(("buf : %s", Buf)); m_pXmlParse.LocateNodeByName(m_pXmlParse.m_parentElement[2], "qmz"); m_InvInfo.m_casign = m_pXmlParse.GetText(); DBG_PRINT(("m_InvInfo.m_casign : %s", m_InvInfo.m_casign.c_str())); } return XML_SUCCESS; }
void DoubleSpanSlider::setSpan(double lower, double upper) { QxtSpanSlider::setSpan(double2int(lower), double2int(upper)); }
void DoubleSpanSlider::setUpperDoubleValue(double upper) { setUpperValue(double2int(upper)); }
void DoubleSpanSlider::setLowerDoubleValue(double lower) { setLowerValue(double2int(lower)); }
void proceedWater(int size, const int xsize, int ysize, int* oldWater, int* newWater) { int x,*xminus1, *yminus1, *xplus1, *yplus1;//, *xminus2, *yminus2, *xplus2, *yplus2; int value; int* oldIndex = oldWater; int* newIndex = newWater; int _size = size; const int _xsize = xsize; int floatMult = (int) (1.05f*65536.); for(x=0; x<xsize; ++x) { xminus1 = oldIndex-1; if(xminus1 < oldWater) xminus1 = oldWater; //xminus2 = oldIndex-2; if(xminus2 < oldWater) xminus2 = oldWater; xplus1 = oldIndex+1; //xplus2 = oldIndex+2; yminus1 = oldWater; //yminus2 = oldIndex; //ahh...not quite right but faster :) yplus1 = oldIndex+xsize; //yplus2 = yplus1+xsize; value = ((*xminus1)+(*xplus1)+(*yminus1)+(*yplus1))/2;//+(*xminus2)+(*xplus2)+(*yminus2)+(*yplus2))/2; value -= (*newIndex); value = double2int((double)value/1.05f); *(newIndex) = value; ++oldIndex; ++newIndex; } //size-= 2*xsize; //mov ecx, 293120 /*_asm { mov ecx, _size mov esi, oldIndex mov edi, newIndex loop_main: mov eax, [esi+1] mov ebx, [esi+_xsize] add eax, ebx mov ebx, [esi-640] add eax, ebx mov ebx, [esi-1] add eax, ebx shr eax, 1 sub eax, [esi] shl eax, 16 xor edx, edx idiv floatMult shr eax, 16 mov [edi], eax inc esi inc edi dec ecx jnz loop_main emms }*/ /*xminus1 = oldIndex-1; xplus1 = oldIndex+1; yminus1 = oldIndex-xsize; yplus1 = oldIndex+xsize;*/ for(x = xsize; x<size -xsize; ++x) { //xminus1 = oldIndex-1; //xplus1 = oldIndex+1; //yminus1 = oldIndex-xsize; //yplus1 = oldIndex+xsize; //xminus2 = xminus1-1; //xplus2 = xplus1+1; //yminus2 = yminus1-xsize; //yplus2 = yplus1 +xsize; xminus1 = oldIndex-1; xplus1 = oldIndex+1; yminus1 = oldIndex-xsize; yplus1 = oldIndex+xsize; value = ((*xminus1++)+(*xplus1++)+(*yminus1++)+(*yplus1++))/2;//+(*xminus2)+(*xplus2)+(*yminus2)+(*yplus2))/4; value -= (*newIndex); value = double2int((double)value/1.05f); *(newIndex) = value; ++oldIndex; ++newIndex; } for(x= size-xsize; x<size; ++x) { xminus1 = oldIndex-1; xplus1 = oldIndex+1; if(xplus1 > oldWater+size-1) xplus1 = oldWater+size-1; yminus1 = oldIndex-xsize; yplus1 = /*oldIndex+xsize; if(yplus1> oldWater+size-1) yplus1 = */oldWater+size-1; /*xminus2 = xminus1-1; //uncomment for slower but better looking water xplus2 = xplus1+1; if(xplus2 > oldWater+size-1) xplus2 = oldWater+size-1; yminus2 = yminus1-xsize; yplus2 = oldIndex;*/ value = ((*xminus1)+(*xplus1)+(*yminus1)+(*yplus1))>>1;/*+(*xminus2)+(*xplus2)+(*yminus2)+(*yplus2)*/ value -= (*newIndex); value = double2int((double)value/1.05f); *(newIndex) = value; ++oldIndex; ++newIndex; } }
//-------------------------------------------------------------- //让Label显示找零打印内容 //-------------------------------------------------------------- UINT8 CProductSaleWin::CashShow(double cash) { DBG_PRINT(("ENTER --CashShow-- FUNCTION!!!")); string strTemp = ""; UINT8 ret; double payback = 0.0; INT32 nCurrentInvNo = g_globalArg->m_curInvVol->m_ieno + 1 - g_globalArg->m_curInvVol->m_remain; double moneySum = ((double)(pSaleData->m_singleInvInfo->m_kphjje))/SUM_EXTENSION; DBG_PRINT(("nCurrentInvNo == %d", nCurrentInvNo)); DBG_PRINT(("cash == %f", cash)); //若输入了现金值 if( (cash<-MINIMUM_PRECISION) || (cash>MINIMUM_PRECISION) ) { if (cash<moneySum) { ret = MONEY_RANDOM; return ret; } if(((UINT64)double2int(cash *SUM_EXTENSION)) >= MAX_MONEY) { ret = MONEY_EXCEED; return ret; } payback = cash - moneySum; //找回现金 } //若未输入现金值 else { cash = moneySum; } DBG_PRINT(("合计 == %f", moneySum)); DBG_PRINT(("g_globalArg->m_curInvVol->m_curInvNo= %u",g_globalArg->m_curInvVol->m_curInvNo)); sprintf(title_arr[0], "当前发票号: %08d", g_globalArg->m_curInvVol->m_curInvNo); if ((pSaleData->m_invtype==RETURN_INV)||(pSaleData->m_invtype==RET_MANUAL_INV)||(pSaleData->m_invtype==RET_SPECIAL_INV)) { sprintf(title_arr[1], "合计:-%.2lf", moneySum); sprintf(title_arr[2], "实付:"); sprintf(title_arr[3], "找回:", payback); } else { sprintf(title_arr[1], "合计:%.2lf", moneySum); sprintf(title_arr[2], "实付:%.2lf", cash); sprintf(title_arr[3], "找回:%.2lf", payback); } #if 0 DBG_PRINT(("g_globalArg->m_invKind->m_nNum = %u",g_globalArg->m_invKind->m_nNum)); if(0 == g_globalArg->m_invKind->m_nNum) { strcpy(title_arr[4], "发票信息上传中"); } else { strcpy(title_arr[4], "发票信息打印中"); } #endif //strcpy(title_arr[4], "发票信息打印中"); strcpy(title_arr[5], "......"); ret = SUCCEED; return ret; }
int DoubleSpanSlider::double2int(double val) const { return double2int(val, min_); }