const bool operator >= (const Fraction& first, const int& i) { Fraction f(i, 1); if (first.num == f.num && first.den == f.den) return true; else { bool greaterThan = Greater(first, f); return greaterThan; } }
void Relation() { Expression(); if(IsRelop(Look)) { Push(); switch(Look) { case '=': Equals();break; case '#': NotEquals();break; case '<': Less();break; case '>': Greater();break; } } }
int main(int argc, const char * argv[]) { Array<int> ints(3); ints[0] = 10; ints[1] = 2; ints[2] = 15; int min = minimum(ints, less); // в min должно попасть число 2 std::cout << "min = " << min << "\n"; int max = minimum(ints, Greater()); // в max должно попасть число 15 std::cout << "max = " << max << "\n"; return 0; }
void Relation() { Expression(); if (IsRelop(Look)) { EmitLn("push rax"); switch(Look) { case '=': Equals(); break; case '#': NotEquals(); break; case '<': Less(); break; case '>': Greater(); break; } EmitLn("add rsp, 8"); EmitLn("cmp rax, 0"); } }
void Relation(void) { message("Relation..."); Expression(); if (IsRelop(Token[0]) ) { message(" (Relation \'%c\')", Token[0]); Push(); switch (Token[0]) { case '=': Equals(); break; case '#': NotEquals(); break; case '<': Less(); break; case '>': Greater(); break; } } }
int main() { generateBase(); for (int i = 0; i < limit; ++i) arr[i] = base[i]; HeapSort(arr, arr + limit); for (int i = 0; i < limit - 1; ++i) if (arr[i] > arr[i + 1]) printf("Error\n"); for (int i = 0; i < limit; ++i) arr[i] = base[i]; HeapSort(arr, arr + limit, Greater()); for (int i = 0; i < limit - 1; ++i) if (arr[i] < arr[i + 1]) printf("Error\n"); printf("OK\n"); return 0; }
/* Parse and Translate a Relation */ void Relation() { Expression(); if (IsRelop(Token)) { Push(); switch (Token) { case '=': Equals(); break; case '<': Less(); break; case '>': Greater(); break; default: break; } } }
void Relation() { Expression(); if (IsRelop(Look)) { EmitLn("pushl %eax"); switch (Look) { case '=': Equals(); break; case '#': NotEquals(); break; case '<': Less(); break; case '>': Greater(); break; } } EmitLn("test %eax, %eax"); }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ BlitAllRectsSD // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Flush changes to screen void CQDBufferedPortDrawBuffer::BlitAllRectsSD() { #if FLUSH_METHOD==1 // see if the rect has changed since last time, if it has then remake the rgn if (!SameRect(boundsRect,mLastBoundsRect)) { mLastBoundsRect=boundsRect; ::RectRgn(mFlushRgn,&mLastBoundsRect); } /* Doesn't seem necessary if (::QDIsPortBufferDirty(sourceBuffer->rec.world)) { ::QDGetDirtyRegion(sourceBuffer->rec.world,mTempRgn); ::UnionRgn(mTempRgn,mFlushRgn,mFlushRgn); }*/ ::QDFlushPortBuffer(sourceBuffer->rec.world,mFlushRgn); #elif FLUSH_METHOD==2 // find largest enclosing rect and flush that if (blitList->usedRects>0) { Rect temp; temp=blitList->rectArray[0]; for (unsigned short counter=1; counter<blitList->usedRects; counter++) { temp.left=Lesser(temp.left,blitList->rectArray[counter].left); temp.top=Lesser(temp.top,blitList->rectArray[counter].top); temp.bottom=Greater(temp.bottom,blitList->rectArray[counter].bottom); temp.right=Greater(temp.right,blitList->rectArray[counter].right); } temp.bottom++; temp.right++; if (!SameRect(temp,mLastBoundsRect)) { mLastBoundsRect=temp; ::RectRgn(mFlushRgn,&mLastBoundsRect); } /* Doesn't seem necessary if (::QDIsPortBufferDirty(sourceBuffer->rec.world)) { ::QDGetDirtyRegion(sourceBuffer->rec.world,mTempRgn); ::UnionRgn(mTempRgn,mFlushRgn,mFlushRgn); }*/ ::QDFlushPortBuffer(sourceBuffer->rec.world,mFlushRgn); } #elif FLUSH_METHOD==3 // build composite rgn and flush that (note, touching rects have already been merged if (blitList->usedRects>0) { ::SetEmptyRgn(mFlushRgn); for (unsigned short counter=0; counter<blitList->usedRects; counter++) { Rect &work=blitList->rectArray[counter]; ++work.right; ++work.bottom; ::RectRgn(mTempRgn,&blitList->rectArray[counter]); --work.right; --work.bottom; ::UnionRgn(mTempRgn,mFlushRgn,mFlushRgn); } /* Doesn't seem necessary if (::QDIsPortBufferDirty(sourceBuffer->rec.world)) { ::QDGetDirtyRegion(sourceBuffer->rec.world,mTempRgn); ::UnionRgn(mTempRgn,mFlushRgn,mFlushRgn); }*/ ::UnlockPortBits(sourceBuffer->rec.world); ::QDFlushPortBuffer(sourceBuffer->rec.world,mFlushRgn); ::LockPortBits(sourceBuffer->rec.world); } #endif }
const bool operator > (const Fraction& first, const Fraction& second) { bool greaterThan = Greater(first, second); return greaterThan; }
/*** Execute this node ***/ Outcome For::execute() { // Check for the for value if(forValue == 0) throw Excep(getLineNumber(), getColumnNumber(), "No variable specified in for loop."); if(forValue->getType() != OP_VARIABLE) throw Excep(getLineNumber(), getColumnNumber(), "For loop must be given a valid variable."); // Store the for value variable Variable* forVar = static_cast<Variable*>(forValue); // If a from value was given, set the counter to this initial value if(from != 0) { // Evaluate the std::auto_ptr<Object> fromEval(from->evaluate()); if(fromEval->getType() != OBJ_INTEGER && fromEval->getType() != OBJ_REAL) throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, fromEval->getType()); Assign(forVar->clone(), fromEval.release()).execute(); } else Assign(forVar->clone(), new Integer(1)).execute(); // Create an Outcome object to store the result Outcome result(S_SUCCESS); do { // Check the while condition, if present if(whileCond != 0) { std::auto_ptr<Object> whileCondEval(whileCond->evaluate()); if(whileCondEval->getType() != OBJ_LOGICAL) throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_LOGICAL, whileCondEval->getType()); bool whileCondResult = static_cast<Logical*>(whileCondEval.get())->getValue(); if(!whileCondResult) break; } // Check the to value if(to != 0) { std::auto_ptr<Object> toEval(to->evaluate()); // Store the step value evaluated std::auto_ptr<Object> stepEval; if(step == 0) stepEval.reset(new Integer(1)); else stepEval.reset(step->evaluate()); // Confirm that the step is an integer if(stepEval->getType() != OBJ_INTEGER && stepEval->getType() != OBJ_REAL) throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, stepEval->getType()); std::auto_ptr<Real> castStep; // Cast the step value to a real if(stepEval->getType() == OBJ_INTEGER) castStep.reset(new Real(static_cast<Integer*>(stepEval.get())->getValue())); else castStep.reset(static_cast<Real*>(stepEval.release())); bool toCondition = false; if(castStep->getValue() > 0) { std::auto_ptr<Object> operation(Greater(forVar->clone(), toEval.release()).evaluate()); toCondition = static_cast<Logical*>(operation.get())->getValue(); } if(castStep->getValue() < 0) { std::auto_ptr<Object> operation(Less(forVar->clone(), toEval.release()).evaluate()); toCondition = static_cast<Logical*>(operation.get())->getValue(); } if(toCondition) break; } // Execute the NodeList of statements result = list->execute(); // Modify forVar based on step if(step == 0) { std::auto_ptr<Object> addOperation(Add(forVar->clone(), new Integer(1)).evaluate()); Assign(forVar->clone(), addOperation.release()).execute(); } else { std::auto_ptr<Object> stepEval(step->evaluate()); if(stepEval->getType() != OBJ_INTEGER && stepEval->getType() != OBJ_REAL) throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, stepEval->getType()); std::auto_ptr<Object> addOperation(Add(forVar->clone(), stepEval.release()).evaluate()); Assign(forVar->clone(), addOperation.release()).execute(); } // Check the until condition, if present if(untilCond != 0) { std::auto_ptr<Object> untilEval(untilCond->evaluate()); if(untilEval->getType() != OBJ_LOGICAL) throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_LOGICAL, untilEval->getType()); bool untilResult = static_cast<Logical*>(untilEval.get())->getValue(); if(untilResult) break; } } while(result.getStatus() == S_SUCCESS); return result; }