xIndirectVoid::xIndirectVoid(const xAddressVoid &src) { Base = src.Base; Index = src.Index; Scale = src.Factor; Displacement = src.Displacement; Reduce(); }
xIndirectVoid::xIndirectVoid(xAddressReg base, xAddressReg index, int scale, s32 displacement) { Base = base; Index = index; Scale = scale; Displacement = displacement; Reduce(); }
Power(int temp[210], int base, int power) { int ndx; while(power--) { for(ndx=0;ndx<210;ndx++) { temp[ndx]= temp[ndx]*base; } Reduce(temp); } }
void GraphicsScene::printPage(int index, int percentual , QPainter &painter, QPrinter * printer) { QPixmap pixmap(painter.viewport().width(),painter.viewport().height()); /* virtual paper */ bool portrait = printer->orientation() == QPrinter::Portrait ? true : false; const qreal wit = qMin(printer->pageRect().width(),printer->paperRect().width()); const qreal hei = qMin(printer->pageRect().height(),printer->paperRect().height()); const qreal faktor_print = qMax(wit,hei) / qMin(wit,hei); const QRect Paper_Rect = printer->pageRect(); qreal onepagescene_HI = sceneRect().width() * faktor_print; if (!portrait) { onepagescene_HI = sceneRect().width() / faktor_print; } QRectF rectScenePiece = QRectF (0.,0.,sceneRect().width(),onepagescene_HI); /* first slice from scene */ const qreal page = sceneRect().height() / onepagescene_HI; /* page need */ int PageSumm = page; if (page > PageSumm) { PageSumm++; /* float to next int */ } if ( index > PageSumm ) { return; /* not having this page */ } qreal InitOnYtop = 0; if (index != 0) { InitOnYtop = rectScenePiece.height() * index; } QRect pagepiece = QRect(0,InitOnYtop,rectScenePiece.width(),rectScenePiece.height()); //////////qDebug() << "### page " << index << "," << percentual << "," << printer->pageRect(); const qreal smallpart = qMax(pixmap.width(),pixmap.height()) / faktor_print; QRectF AFormatPaper; /* Paper dimension from printer Faktor run */ if (portrait) { AFormatPaper = QRect(0,0,smallpart,qMax(pixmap.width(),pixmap.height())); } else { AFormatPaper = QRect(0,0,qMax(pixmap.width(),pixmap.height()),smallpart); } QRectF ZoomFaktorPage = Reduce(AFormatPaper,percentual); /* zoom rect */ QRect WhitePaper = CenterRectSlaveFromMaster(pixmap.rect(),AFormatPaper).toRect(); QRect RenderPage = CenterRectSlaveFromMaster(pixmap.rect(),ZoomFaktorPage).toRect(); painter.fillRect(painter.viewport(),QBrush(Qt::lightGray)); /* device to cover */ painter.fillRect(WhitePaper,QBrush(Qt::white)); /* paper */ /////////painter.fillRect(RenderPage,QBrush(Qt::red)); /* page result */ render(&painter,RenderPage,pagepiece,Qt::KeepAspectRatio); }
/*--------------------------------------------------------------------- * Function: Add * Purpose: Add two fractions * In args: frac2 * In/out arg: frac1 += frac2 */ void Add(frac_t frac1, unsigned frac2) { if (frac1->denom >= frac2) { Add_to_num(frac1, frac1->denom - frac2); } else { Left_shift_num(frac1, frac2 - frac1->denom); Add_to_num(frac1, 0); frac1->denom = frac2; } Reduce(frac1); } /* Add */
Fraction::Fraction(int n, int d) { if (d < 0) { numerator = -n; denominator = -d; } else { numerator = n; denominator = d; } Reduce(); }
/*--------------------------------------------------------------------- * Function: Equals * Purpose: Determine whether two fractions are equal * In/out args: frac1, frac2 * Note: * 1. Instead of cross-multiplying, we reduce both fractions and * check for equality of numerator and denominator: this may * avoid some overflow issues. */ int Equals(frac_t frac, unsigned val) { Reduce(frac); if (frac->denom != 0) return 0; // false else if (frac->most_sig_bit > sizeof(unsigned)) return 0; else if (Equals_bit_array(frac, val)) return 1; else return 0; } /* Equals */
Fraction Fraction::operator *= (const Fraction& rhs) { if (__builtin_mul_overflow(numerator, rhs.numerator, &numerator)) goto err; if (__builtin_mul_overflow(DenominatorAsInt(), rhs.DenominatorAsInt(), &denominator)) goto err; Reduce(); return *this; err: valid = false; return *this; }
Fraction::Fraction(int whole, int num, unsigned denom) : numerator(std::abs(num) + std::abs(whole) * denom), denominator(denom), realValue(0), valid(denom != 0) { if (num < 0 || whole < 0) { numerator *= -1; } CalculateRealValue(); Reduce(); }
ID3DTexture2D* TW_LoadTextureFromTexture ( ID3DTexture2D* t_from, D3DFORMAT& t_dest_fmt, int levels_2_skip, u32& w, u32& h ) { // Calculate levels & dimensions ID3DTexture2D* t_dest = NULL; D3DSURFACE_DESC t_from_desc0 ; R_CHK (t_from->GetLevelDesc (0,&t_from_desc0)); int levels_exist = t_from->GetLevelCount(); int top_width = t_from_desc0.Width; int top_height = t_from_desc0.Height; Reduce (top_width,top_height,levels_exist,levels_2_skip); // Create HW-surface if (D3DX_DEFAULT==t_dest_fmt) t_dest_fmt = t_from_desc0.Format; R_CHK (D3DXCreateTexture( HW.pDevice, top_width,top_height, levels_exist,0,t_dest_fmt, D3DPOOL_MANAGED,&t_dest )); // Copy surfaces & destroy temporary ID3DTexture2D* T_src= t_from; ID3DTexture2D* T_dst= t_dest; int L_src = T_src->GetLevelCount ()-1; int L_dst = T_dst->GetLevelCount ()-1; for (; L_dst>=0; L_src--,L_dst--) { // Get surfaces IDirect3DSurface9 *S_src, *S_dst; R_CHK (T_src->GetSurfaceLevel (L_src,&S_src)); R_CHK (T_dst->GetSurfaceLevel (L_dst,&S_dst)); // Copy R_CHK (D3DXLoadSurfaceFromSurface(S_dst,NULL,NULL,S_src,NULL,NULL,D3DX_FILTER_NONE,0)); // Release surfaces _RELEASE (S_src); _RELEASE (S_dst); } // OK w = top_width; h = top_height; return t_dest; }
void* ExecReduce(void* mapReduce) { writeToLogCreation(REDUCE_THREAD_ID); auto mapReduceBase = (MapReduceBase*) mapReduce; try { OUT_ITEMS_LIST *outItemsList = new OUT_ITEMS_LIST; pthread_mutex_lock(&activeThreadsMutex); levelThreeVec.push_back(std::pair<pthread_t, OUT_ITEMS_LIST *> (pthread_self(), outItemsList)); pthread_mutex_unlock(&activeThreadsMutex); while (!reductionFinished) { if (pthread_mutex_lock(&idxMutex)) { mapReduceFrameworkFailure("pthread_mutex_lock"); } ShuffledMap::iterator shuffledIterator = shuffledIter; for (int i = 0; i < 10; ++i) { if (shuffledIter != shuffledMap.end()) { shuffledIter++; } else { reductionFinished = true; break; } } if (pthread_mutex_unlock(&idxMutex)) { mapReduceFrameworkFailure("pthread_mutex_unlock"); } for (int j = 0; j < 10; ++j) { if (shuffledIterator == shuffledMap.end()) { break; } mapReduceBase->Reduce(shuffledIterator->first, (shuffledIterator->second)); shuffledIterator++; } } writeToLogTermination(REDUCE_THREAD_ID); return NULL; }catch(std::bad_alloc e){ mapReduceFrameworkFailure("new"); } return nullptr; }
int main(void) { char command; frac_t frac; unsigned other_frac, test_eq, u1, u2; MPI_Init(NULL, NULL); frac = Alloc_frac(); printf("Enter a command (a, r, e, d, s, q)\n"); scanf(" %c", &command); while (command != 'q') { switch(command) { case 'a': printf("Enter log denom of a frac\n"); scanf("%u", &other_frac); Add(frac, other_frac); Print_frac(frac, 0, "Sum = "); break; case 'r': Reduce(frac); Print_frac(frac, 0, "Reduced frac = "); break; case 'e': printf("Enter an unsigned int\n"); scanf("%u", &test_eq); if (Equals(frac, test_eq)) printf("They're equal\n"); else printf("They're not equal\n"); break; case 'd': Debug_print(frac); break; case 's': // Assign printf("Enter two unsigned ints\n"); scanf("%u %u", &u1, &u2); Assign(frac, u1, u2); Print_frac(frac, 0, "We created = "); break; default: printf("I didn't understand %c\n", command); break; } /* switch */ printf("Enter a command (a, r, e, d, s, q)\n"); scanf(" %c", &command); } /* while */ Free_frac(frac); MPI_Finalize(); return 0; } /* main */
double Expression::GetValue(vector<vector<Expression> >& sSheet) { if (_color == WHITE) { _color = RED; deque<string> tokens = SplitDeq(_origExp, ' '); _value = tokens.size() == 0 ? 0 : Reduce(sSheet, tokens); _color = GREEN; _origExp.clear(); return _value; } else if (_color == RED) { throw runtime_error("Circular Reference detected"); } else { return _value; } }
__kernel void build_combo( ulong_t start_offset, __constant item_t db_items[], llf_criteria cfg, uint_t db_len, uint_t combo_len, __local setmax_t *unique, __local result_t *scratch, __global result_t *result) { result_t dps = build_combo_m(db_items, &cfg, start_offset + get_global_id(0), db_len, combo_len, unique); Reduce(dps, scratch, result); }
void Analyze(ValueNode& root, const TokenList& token_list) { #if 0 if(token_list.empty()) throw LoggedEvent("Empty token list found;", Alert); #endif if(Validate(token_list.begin(), token_list.end()) != token_list.end()) throw LoggedEvent("Redundant ')' found.", Alert); const auto res(Reduce(root, token_list.begin(), token_list.end())); yassume(res == token_list.end()); }
// Method to push (shift element into the stack and reduce if reqd) int ReorderingStack::ShiftReduce(const Range &input_span) { int distance; // value to return: the initial distance between this and previous span // stack is empty if (m_stack.empty()) { m_stack.push_back(input_span); return input_span.GetStartPos() + 1; // - (-1) } // stack is non-empty Range prev_span = m_stack.back(); //access last element added //calculate the distance we are returning if (input_span.GetStartPos() > prev_span.GetStartPos()) { distance = input_span.GetStartPos() - prev_span.GetEndPos(); } else { distance = input_span.GetEndPos() - prev_span.GetStartPos(); } if (distance == 1) { //monotone m_stack.pop_back(); Range new_span(prev_span.GetStartPos(), input_span.GetEndPos()); Reduce(new_span); } else if (distance == -1) { //swap m_stack.pop_back(); Range new_span(input_span.GetStartPos(), prev_span.GetEndPos()); Reduce(new_span); } else { // discontinuous m_stack.push_back(input_span); } return distance; }
Fraction::Fraction(float val) : realValue(0), valid(true) { double intpart = std::floor(val); double fracpart = val - intpart; const long precision = 1000000; const int gcd = GCD(static_cast<long>(std::round(fracpart * precision)), precision); denominator = precision / gcd; numerator = std::round(fracpart * precision) / gcd + (intpart * denominator); CalculateRealValue(); Reduce(); }
void Expr::Parse(void) { Expr *e = AllocExpr(); e->op = ALL_RESOLVED; PushOperator(e); for(;;) { Expr *n = Next(); if(!n) throw "end of expression unexpected"; if(n->op == CONSTANT) { PushOperand(n); Consume(); } else if(n->op == PAREN && n->c == '(') { Consume(); Parse(); n = Next(); if(n->op != PAREN || n->c != ')') throw "expected: )"; Consume(); } else if(n->op == UNARY_OP) { PushOperator(n); Consume(); continue; } else if(n->op == BINARY_OP && n->c == '-') { // The minus sign is special, because it might be binary or // unary, depending on context. n->op = UNARY_OP; n->c = 'n'; PushOperator(n); Consume(); continue; } else { throw "expected expression"; } n = Next(); if(n && n->op == BINARY_OP) { ReduceAndPush(n); Consume(); } else { break; } } while(TopOperator()->op != ALL_RESOLVED) { Reduce(); } PopOperator(); // discard the ALL_RESOLVED marker }
unsigned int CColorQuantization::Done(COLORREF colorTable[16]) { while (m_nColorCount > m_nMaxCount) Reduce(); unsigned int index = 0; for (const auto &it : m_setLeafParent) for (unsigned int i = (it << 3) + 1, j = i + 8; i < j; ++i) if (m_cNodes[i].count&&m_cNodes[i].leaf) { m_cNodes[i].red = (m_cNodes[i].red + (m_cNodes[i].count >> 1)) / m_cNodes[i].count; m_cNodes[i].green = (m_cNodes[i].green + (m_cNodes[i].count >> 1)) / m_cNodes[i].count; m_cNodes[i].blue = (m_cNodes[i].blue + (m_cNodes[i].count >> 1)) / m_cNodes[i].count; m_cNodes[i].count = 1; m_cNodes[i].index = index; colorTable[index++] = RGB(m_cNodes[i].red, m_cNodes[i].green, m_cNodes[i].blue); }
TLCIter Reduce(ValueNode& node, TLCIter b, TLCIter e) { while(b != e && *b != ")") if(*b == "(") { auto nd(MakeNode(to_string(node.GetSize()))); auto res(Reduce(nd, ++b, e)); if(res == e || *res != ")") throw LoggedEvent("Redundant '(' found.", Alert); node += std::move(nd); b = ++res; } else node += {0, to_string(node.GetSize()), *b++}; return b; }
Fraction Fraction::operator += (const Fraction& rhs) { const int lcm = LCM(DenominatorAsInt(), rhs.DenominatorAsInt()); int A = 0, B = 0; if (__builtin_mul_overflow(numerator / DenominatorAsInt(), lcm, &A)) goto err; if (__builtin_mul_overflow(rhs.numerator / rhs.DenominatorAsInt(), lcm, &B)) goto err; if (__builtin_add_overflow(A, B, &numerator)) goto err; denominator = lcm; Reduce(); return *this; err: valid = false; return *this; }
const RichTable::TabLayout& RichTable::Realize(RichContext rc) const { if(rc.py != cpy || rc.page != cpage) { rc.py.y += format.before; if(rc.py.y > rc.page.bottom) { rc.py.y = rc.page.top; rc.py.page++; } cpage = rc.page; cpy = rc.py; Reduce(rc); clayout.page = rc.page; clayout.hasheader = false; clayout.sz = GetSize(); if(format.header && cell.GetCount()) { int hy = min(format.header, cell.GetCount()); RichContext nrc = rc; nrc.py.page = 0; nrc.py.y = clayout.page.top; clayout.header = Realize(nrc, hy); if(clayout.header[0].py.page == clayout.header[hy - 1].pyy.page) { Layout x = Realize(rc, cell.GetCount()); if(cell.GetCount() > hy && rc.py.page != x[hy].py.page) { rc.py.page++; rc.py.y = rc.page.top; } clayout.hasheader = true; rc.page.top = clayout.page.top = clayout.header[hy - 1].pyy.y + format.grid; } } clayout.page0 = rc.py.page; (Layout&)clayout = Realize(rc, cell.GetCount()); if(format.keep && cell.GetCount()) { if(clayout[0].py.page != clayout[cell.GetCount() - 1].pyy.page) { rc.py.page++; rc.py.y = rc.page.top; } clayout.page0 = rc.py.page; (Layout&)clayout = Realize(rc, cell.GetCount()); } } return clayout; }
Fraction Fraction::operator -= (const Fraction& rhs) { const int lcm = LCM(DenominatorAsInt(), rhs.DenominatorAsInt()); int A = 0, B = 0; if (__builtin_mul_overflow(numerator / DenominatorAsInt(), lcm, &A)) goto err; if (__builtin_mul_overflow(rhs.numerator / rhs.DenominatorAsInt(), lcm, &B)) goto err; if (__builtin_sub_overflow(A, B, &numerator)) goto err; denominator = lcm; Reduce(); // std::cout << "result: " << *this << std::endl; return *this; err: valid = false; return *this; }
bool Syntaxer::CreateSyntaxTree(SyntaxNode*& root, FileScanner* fileScanner) { TokenPosition position = { 0 }; stack_->push(0, nullptr, NativeSymbols::zero); LRAction action = { LRActionShift }; void* addr = nullptr; GrammarSymbol symbol = nullptr; do { if (action.type == LRActionShift && !(symbol = ParseNextSymbol(position, addr, fileScanner))) { break; } action = p_.lrTable.GetAction(stack_->states.back(), symbol); if (action.type == LRActionError && !Error(symbol, position)) { break; } if (action.type == LRActionShift) { Shift(action.parameter, addr, symbol); } else if (action.type == LRActionReduce) { if (!Reduce(action.parameter)) { break; } } } while (action.type != LRActionAccept); if (action.type == LRActionAccept) { root = (SyntaxNode*)stack_->values.back(); stack_->clear(); } else { CleanupOnFailure(); } return action.type == LRActionAccept; }
// Reduction reduced a set of leaves determined by their keys stored // in leafKeys. Integer redNumber is for debugging only. bool PlanarSubgraphPQTree:: Reduction(SListPure<PlanarLeafKey<whaInfo*>*> &leafKeys, SList<PQLeafKey<edge,whaInfo*,bool>*> &eliminatedKeys, int redNumber) { SListPure<PQLeafKey<edge,whaInfo*,bool>*> castLeafKeys; SListIterator<PlanarLeafKey<whaInfo*>* > it; for (it = leafKeys.begin(); it.valid(); ++it) { castLeafKeys.pushBack((PQLeafKey<edge,whaInfo*,bool>*) *it); #ifdef OGDF_DEBUG if (int(ogdf::debugLevel) >= int(dlHeavyChecks)) { cout << (*it)->print() << endl; } #endif } determineMinRemoveSequence(castLeafKeys,eliminatedKeys); removeEliminatedLeaves(eliminatedKeys); SListIterator<PQLeafKey<edge,whaInfo*,bool>* > itn = castLeafKeys.begin(); SListIterator<PQLeafKey<edge,whaInfo*,bool>* > itp = itn++; for (; itn.valid();) { if ((*itn)->nodePointer()->status()== WHA_DELETE) { itn++; castLeafKeys.delSucc(itp); } else itp = itn++; } if ((*castLeafKeys.begin())->nodePointer()->status() == WHA_DELETE) castLeafKeys.popFront(); return Reduce(castLeafKeys,redNumber); }
static inline Fractional< Natural > ReducingSubtract(const Fractional< Natural > &left, const Fractional< Natural > &right) { Fractional< Natural > result; Natural factor; if (left.denominator == right.denominator) { result.numerator = left.numerator - right.numerator; result.denominator = left.denominator; } else { factor = LeastCommonMultiple(left.denominator, right.denominator); if (left.denominator < right.denominator) { factor /= left.denominator; result.numerator = left.numerator * factor - right.numerator; result.denominator = right.denominator; } else { factor /= right.denominator; result.numerator = left.numerator - right.numerator * factor; result.denominator = left.denominator; } } return Reduce(result); }
double* CLinearSystem::Solve() { printf("system to solve: \n"); PrettyPrint(); printf("==== solving ==== \n"); Normalize(); Augment(); Reduce(); Augment(); PrettyPrint(); if(m_result != NULL) { delete m_result; } m_result = new double[m_n]; for(int n = 0; n < m_n; n++) { m_result[n] = Get(n,m_m-1); } return m_result; }
__kernel void metric_area( ulong_t linext_offset, lattice_info info, __global ideal_t *linext, DB, llf_criteria cfg, __local ideal_t *pasv_scratch, __local result_t* scratch, __global result_t* result) { result_t metric = { 0, 0 }; count_t nth_extension = linext_offset + get_global_id(0); linext += info.linext_width * get_global_id(0); pasv_scratch += PASV_SCRATCH_LEN(info.linext_width) * get_local_id(0); ZERO_INIT(pasv_scratch, PASV_SCRATCH_LEN(info.linext_width)); metric = RateBuildpath(linext, db_items, &cfg, pasv_scratch, &info, nth_extension); Reduce(metric, scratch, result); }
int main() { char an; do { int Num, Denom, Num2, Denom2 = 0; ReadFraction(Num, Denom,Num2,Denom2); Reduce(Num, Denom, Num2, Denom2); AddFraction(Num, Denom, Num2, Denom2); DisplayFraction(Num, Denom); cout << endl; cout <<"Would you like to do another fraction? "; cin >> an; cout << endl; } while ((an == 'y') || (an == 'Y')); return(0); }
void AddFraction(int &Num, int &Denom, int &Num2, int &Denom2) /* This function is called after Reduce. This function adds the two fractions Reduce() reduced Pre: Two Fractions Post: One reduced fraction */ { if (Denom != Denom2) { Num = Num * Denom2; Num2 = Num2 * Denom; Denom = Denom * Denom2; Denom2 = Denom2 * Denom; Num = Num + Num2; } else { Num = Num + Num2; } Reduce(Num, Denom); }