void Queue<Object>::enqueue( const Object & x ) { if( isFull( ) ) throw Overflow( ); increment( back ); theArray[ back ] = x; currentSize++; }
template <class T> void AQueue<T>::enqueue (const T &new_item) { if (!is_full()){ queue_[tail_] = new_item; count_++; tail_ = increment(tail_); } else throw Overflow(); }
void BinaryHeap<Comparable>::insert( const Comparable & x ) { if( isFull( ) ) throw Overflow( ); // Percolate up int hole = ++currentSize; for( ; hole > 1 && x < array[ hole / 2 ]; hole /= 2 ) array[ hole ] = array[ hole / 2 ]; array[ hole ] = x; }
void Video::NewLine() { Video::Private::PrintPosition += Video::Private::NewLineCounter; if (Video::Private::PrintPosition > 1999) { Overflow(); Video::Private::PrintPosition = 1920; } Video::Private::MoveCursor(Video::Private::PrintPosition); Video::Private::NewLineCounter = 80; }
void List::remove(Node* ptr) { if (ptr == head) pop_front(); else { Node *tmp = head; while(tmp && tmp->next != ptr) tmp = tmp->next; if (!tmp || !ptr) throw Overflow(); tmp->next = ptr->next; delete ptr; } }
inline std::string libNetwork::packet::getHexString ( int string_cursor, int read_byte ) { std::string temp; temp.reserve ( read_byte * 2 ); if ( string_cursor + read_byte > this->getPacketLength() ) throw Overflow(); for ( int i = string_cursor * 2; i < ( string_cursor * 2 ) + ( read_byte * 2 ); i++ ) { temp += rawData[i]; } return temp; }
void STLQueue_Adapter<T, QUEUE>::enqueue (const T &new_item) { // You fill in here. try{ queue_.push(new_item); } // @@ Don't catch ... - just catch the std::bad_alloc exception. catch(std::bad_alloc){ throw Overflow(); } }
void List::insert(int pos, const int& n) { if (pos == 0) push_front(n); else if (pos > 0) { Node *tmp = head; while(tmp && --pos) tmp = tmp->next; if (tmp == 0) throw Overflow(); Node *newNode = new Node(n, tmp->next); tmp->next = newNode; } else throw BadArguments(); }
//Insere o elemento x no fim da fila F. void InsereFila(TipoDoElemento x, Fila *pF){ //Se em seu proximo indicie, fim está na mesma posição que inicio e a fila não está vazia, deu overflow if(((pF->fim + 1) % MAX) == pF->inicio && pF->vazia == 0) { Overflow(); exit(1); } else //Sem overflow, atualizo o indice de fim e adiciono o elemento. Se a fila estava vazia, indico que não está mais vazia agora. pF->fim = (pF->fim + 1) % MAX; pF->elementos[pF->fim] = x; if (ehFilaVazia(pF) == 1) pF->vazia = 0; }
void BinaryHeap<Comparable>::insert( Comparable & x ) { if( isFull( ) ) throw Overflow( ); // Percolate up int hole = ++currentSize; int a = x.distance; int b = array[hole/2].distance; for( ; hole > 1 && a<b; hole /= 2 ) array[ hole ] = array[ hole / 2 ]; array[ hole ] = x; }
void simnet() { // Input and output signals and buses Signal A(8); Signal B(8); Signal Sum(8, "Sum"); Signal Carry(1, "C"); Signal Overflow(1, "V"); // A bus input switches Switch("1a", A[7], '7'); Switch("1a", A[6], '6'); Switch("1a", A[5], '5'); Switch("1a", A[4], '4'); Switch("1a", A[3], '3'); Switch("1a", A[2], '2'); Switch("1a", A[1], '1'); Switch("1a", A[0], '0'); Space(SD("1a", "A Bus")); // B bus input switches Switch("3a", B[7], '&'); Switch("3a", B[6], '^'); Switch("3a", B[5], '%'); Switch("3a", B[4], '$'); Switch("3a", B[3], '#'); Switch("3a", B[2], '@'); Switch("3a", B[1], '!'); Switch("3a", B[0], ')'); Space(SD("3a", "B Bus")); Add8("2b", //inputs: A, B, //outputs: Sum, Carry, Overflow ); int parts[] = {4}; Probe("1c-2c.1a", Sum, 1, parts ); Space(SD("3c", "Sum")); Space(SD("3b")); Probe("3b", Overflow); Space(SD("3b", "Overflow")); Probe("3c", Carry); Space(SD("3c", "Carry")); }
void List::remove(int pos) { if (pos == 0) pop_front(); else if (pos > 0) { Node *tmp = head; while(tmp && --pos) tmp = tmp->next; if (!tmp || !tmp->next) throw Overflow(); Node *oldNode = tmp->next; tmp->next = oldNode->next; delete oldNode; } else throw BadArguments(); }
void Video::Print(string text) { word PrintLength = CalculatePrintLength(text); byte* writelocation = (byte*)(VidMem + (Video::Private::PrintPosition*2)); for (word i = 0; i < PrintLength; i++) { Video::Private::NewLineCounter = Video::Private::NewLineCounter - 1; if (Video::Private::NewLineCounter == 0) Video::Private::NewLineCounter = 80; if ((byte)*text == '\r') { text++; Video::Private::NewLineCounter++; goto Escape; } if ((byte)*text == '\n') { Video::Private::PrintPosition = (((dword)writelocation - VidMem) / 2); Video::Private::PrintPosition += (Video::Private::NewLineCounter) + 1; writelocation = (byte*)(VidMem + (Video::Private::PrintPosition*2)); Video::Private::NewLineCounter = 80; text++; goto Escape; } *writelocation = (byte)*text; writelocation++; *writelocation = Video::Private::Colour; writelocation++; text++; Escape: if ((dword)writelocation > 0xB8F9F) { Overflow(); Video::Private::MoveCursor(1920); writelocation = (byte*)0xB8F00; } } dword newprintlocation = ((dword)writelocation - VidMem); newprintlocation = newprintlocation / 2; Video::Private::PrintPosition = newprintlocation; Video::Private::MoveCursor(newprintlocation); }
int main(void) { long m, n, sum; printf("Enter two ints (both 0 to quit)\n"); printf("fedcba9876543210 fedcba9876543210\n"); scanf("%lx%lx", &m, &n); while (m != 0 || n != 0) { sum = m + n; printf("The C sum of 0x%lx and 0x%lx is 0x%lx\n", m, n, sum); if (Overflow(m,n)) printf("The sum overflowed\n\n"); else printf("The sum didn't overflow\n\n"); printf("Enter two ints (both 0 to quit)\n"); printf("fedcba9876543210 fedcba9876543210\n"); scanf("%lx%lx", &m, &n); } return 0; } /* main */
longint longint::add(longint Q){ longint * long1 = new longint(list()); longint * long2 = new longint(Q.list()); longint * sum = new longint(); //cout << Getsign() << Q.Getsign() << '\n'; if(Getsign() == Q.Getsign()){ //cout << "same" << '\n'; char addsign = Getsign(); sum->Setsign(addsign); struct Node * nod1; struct Node * nod2; nodresult = 0; int overflow = 0; nod1 = long1->list().GetLast(); nod2 = long2->list().GetLast(); //cout<<long1->list().getValue(nod1)<< '\n'; //cout<<long2->list().getValue(nod2)<< '\n'; while(long1->list().getValue(nod1) != -1 && long2->list().getValue(nod2) != -1){ nodresult = long1->list().getValue(nod1) + long2->list().getValue(nod2) + overflow; //cout<<nodresult<< '\n'; nod1 = long1->list().nextLeft(nod1); nod2 = long2->list().nextLeft(nod2); overflow = Overflow(nodresult); //cout<<overflow<< '\n'; //cout<<nodresult<< '\n'; sum->list().insertFront(nodresult); } while(long1->list().getValue(nod1) != -1){ nodresult = long1->list().getValue(nod1) + overflow; nod1 = long1->list().nextLeft(nod1); overflow = Overflow(nodresult); sum->list().insertFront(nodresult); } while(long2->list().getValue(nod2) != -1){ nodresult = long2->list().getValue(nod2) + overflow; nod2 = long2->list().nextLeft(nod2); overflow = Overflow(nodresult); sum->list().insertFront(nodresult); } if(overflow != 0){ nodresult = overflow; sum->list().insertFront(nodresult); } return *sum; } else{ if(Getsign() == '-'){ return long2->subtract(*long1); } else{ return long1->subtract(*long2); } cout << "different" << '\n'; } //long2->Print(); //long1->Print(); return *sum; }
HRESULT ArmEmulator::Execute( CLR_UINT64 steps ) { TINYCLR_HEADER(); // // Prepare Interop detours. // { for(AddressToHandlerMapIter it = m_callInterop.begin(); it != m_callInterop.end(); it++) { ApplyInterop( it->second ); } } m_fStopExecution = false; for(CLR_UINT64 i=0; i<steps; i++) { CLR_UINT32 pc = m_pc; CLR_UINT32 instruction; bool fRes; // // Special case: if we pass by the reset vector, reload the interop breakpoints. // if(pc == 0) { for(AddressToHandlerMapIter it = m_callInterop.begin(); it != m_callInterop.end(); it++) { ApplyInterop( it->second ); } } { if(MemoryLoad( pc, instruction, DATATYPE_U4 ) == false) { CLR_Debug::Printf( "FETCH ABORT at 0x%08x %I64d\r\n", pc, i ); TINYCLR_SET_AND_LEAVE(CLR_E_FAIL) } } #if defined(ARMEMULATOR_MONITOR_CALLS) if(m_fMonitorCalls) { CLR_RT_AddressToSymbolMapIter it; size_t pos = m_callQueue.size(); CLR_UINT32 sp = m_registers[ ArmProcessor::c_register_sp ]; for(size_t pos2=pos; pos2-- > 0; ) { TrackCall& tc = m_callQueue[ pos2 ]; if((tc.m_lr == pc && tc.m_sp == sp) || (tc.m_sp && tc.m_sp < sp)) { while(pos-- > pos2) { TrackCall& tc2 = m_callQueue[ pos ]; tc2.m_te.End( this ); CLR_Debug::Printf( "%*s<<<< CALL %S (%s)\r\n", pos, "", tc2.m_name->c_str(), tc2.m_te.ToString() ); m_callQueue.pop_back(); } pos++; } else { break; } } it = m_symdef_Inverse.find( pc ); if(it != m_symdef_Inverse.end()) { while(true) { if(it->second == L"NoClearZI_ER_RAM") break; if(it->second == L"ClearZI_ER_RAM" ) break; if(it->second == L"ARM_Vectors" ) break; m_callQueue.resize( pos + 1 ); TrackCall& tc = m_callQueue[ pos ]; tc.m_pc = pc; tc.m_lr = m_registers[ ArmProcessor::c_register_lr ]; tc.m_sp = sp; tc.m_name = &it->second; tc.m_te.Start( this ); CLR_Debug::Printf( "%*s>>>> CALL %S\r\n", pos, "", tc.m_name->c_str() ); break; } } } #endif //--//--//--//--//--//--//--//--//--//--//--// if(instruction == c_InteropOpcode) { // // Copy, not reference, the entry can be removed from the map by the interop code. // TrackInterop ti = m_callInterop[ pc ]; if(m_fStopExecution) { break; } if(ti.m_call) { if((this->*(ti.m_call))()) continue; instruction = ti.m_op; } if(m_fStopExecution) { break; } } //--//--//--//--//--//--//--//--//--//--//--// #if defined(ARMEMULATOR_MONITOR_OPCODES) if(m_fMonitorOpcodes) { ArmProcessor::Opcode op; char rgBuf[ 128 ]; op.InitText( rgBuf, MAXSTRLEN(rgBuf), pc ); if(op.Decode( instruction ) == false) { CLR_Debug::Printf( "DECODE ABORT at 0x%08x %I64d\r\n", pc, i ); TINYCLR_SET_AND_LEAVE(CLR_E_FAIL) } fRes = op.CheckConditions( *this ); op.AppendText( "%-9I64d %-9I64d 0x%08x: %08x %c%c%c%c %c ", i, m_clockTicks, pc, instruction, Negative() ? 'N' : '-', Zero() ? 'Z' : '-', Carry() ? 'C' : '-', Overflow() ? 'V' : '-', fRes ? ' ' : '*' ); op.Print(); CLR_Debug::Printf( "%s\r\n", rgBuf ); }
int mul(int a, int b) { if (a == 0 || b == 0) return 0; if (numeric_limits<int>::max() / a < b) throw Overflow(); return a * b; }
int add(int a, int b) { if (numeric_limits<int>::max() - a < b) throw Overflow(); return a + b; }
longint longint::multiply(longint Q){ longint * long1 = new longint(list()); longint * long2 = new longint(Q.list()); longint * mult = new longint("0"); //mult->Setsign('+'); if(long1->list().getValue(long1->list().GetLast()) == 0 && long1->list().getValue(long1->list().nextLeft(long1->list().GetLast())) == -1){ mult->list().insertFront(0); } else if(long2->list().getValue(long2->list().GetLast()) == 0 && long2->list().getValue(long2->list().nextLeft(long2->list().GetLast())) == -1){ mult->list().insertFront(0); } else{ struct Node * nod1; struct Node * nod2; nodresult = 0; nod1 = long1->list().GetLast(); nod2 = long2->list().GetLast(); int data1 = long1->list().getValue(nod1); int data2 = long2->list().getValue(nod2); //mult->list().insertFront(0); //mult->Print(); //mult->Setsign('+'); //mult->Print(); int counter2 = 0; int counter = 0; int overflow; while(long2->list().getValue(nod2) != -1){ while(long1->list().getValue(nod1) != -1){ longint * adder = new longint(); nodresult = long2->list().getValue(nod2)*long1->list().getValue(nod1); overflow = Overflow(nodresult); if(overflow > 0){ adder->list().insertFront(nodresult); adder->list().insertFront(overflow); int i = 0; for( i = 0; i < counter; i++){ adder->list().insertBack(0); } i = 0; for( i = 0; i < counter2; i++){ adder->list().insertBack(0); } //adder->Print(); } else if(overflow == 0 && nodresult > 0){ adder->list().insertFront(nodresult); int i = 0; for( i = 0; i < counter; i++){ adder->list().insertBack(0); } i = 0; for( i = 0; i < counter2; i++){ adder->list().insertBack(0); } //adder->Print(); } else{ adder->list().insertFront(0); //adder->Print(); } //adder->Print(); //mult->Print(); longint * RSLT = new longint("0"); *mult = adder->add(*mult); //mult->Print(); nod1 = long1->list().nextLeft(nod1); counter++; adder=NULL; delete adder; } nod2 = long2->list().nextLeft(nod2); counter2++; counter = 0; nod1 = long1->list().GetLast(); } } if(Getsign() == '-' && Q.Getsign() == '+'){ mult->Setsign('-'); } if(Getsign() == '+' && Q.Getsign() == '-'){ mult->Setsign('-'); } return *mult; }