Exemplo n.º 1
0
int power(struct NUMBER *a,struct NUMBER *b,struct NUMBER *c)
{
	int res = 0;
	struct NUMBER tmp_b,tmp_c,tmp;

	if(isZero(b) == 0)//bが最初から0ならば
	{
		setInt(c,1);//cを1に
		return(0);//n^0は(0を除いて)必ず1になるため
	}

	if(getSign(b) == -1)//bが負なら
		return(-1);

	copyNumber(b,&tmp_b);//bが破壊されないようにtmp_bに
	copyNumber(a,c);//aをcにコピー、cの初期値をaとする

	copyNumber(&tmp_b,&tmp);//tmp_bにtmpを代入、グダグダなのはわかってる。
	decrement(&tmp,&tmp_b);//もうすでにcにはa^1があるので、1をまず引く

	while(1)
	{
		if(isZero(&tmp_b) == 0)
			break;//bが0になったら終了
		copyNumber(c,&tmp_c);//tmp_cに現在のcの値を代入する
		res = multiple(a,&tmp_c,c);
		if(res == -1)
			break;
		
		copyNumber(&tmp_b,&tmp);//tmp_bにtmpを代入、グダグダなのはわかってる。
		decrement(&tmp,&tmp_b);//tmp_b--;を実行してます
	}
	return(res);
}
Exemplo n.º 2
0
double FIRFilter(TRMFIRFilter *filter, double input, int needOutput)
{
    if (needOutput) {
	int i;
	double output = 0.0;

	/*  PUT INPUT SAMPLE INTO DATA BUFFER  */
	filter->FIRData[filter->FIRPtr] = input;

	/*  SUM THE OUTPUT FROM ALL FILTER TAPS  */
	for (i = 0; i < filter->numberTaps; i++) {
	    output += filter->FIRData[filter->FIRPtr] * filter->FIRCoef[i];
	    filter->FIRPtr = increment(filter->FIRPtr, filter->numberTaps);
	}

	/*  DECREMENT THE DATA POINTER READY FOR NEXT CALL  */
	filter->FIRPtr = decrement(filter->FIRPtr, filter->numberTaps);

	/*  RETURN THE OUTPUT VALUE  */
	return output;
    } else {
	/*  PUT INPUT SAMPLE INTO DATA BUFFER  */
	filter->FIRData[filter->FIRPtr] = input;

	/*  ADJUST THE DATA POINTER, READY FOR NEXT CALL  */
	filter->FIRPtr = decrement(filter->FIRPtr, filter->numberTaps);

	return 0.0;
    }
}
Exemplo n.º 3
0
double
FIRFilter::filter(double input, int needOutput)
{
	if (needOutput) {
		int i;
		double output = 0.0;

		/*  PUT INPUT SAMPLE INTO DATA BUFFER  */
		data_[ptr_] = input;

		/*  SUM THE OUTPUT FROM ALL FILTER TAPS  */
		for (i = 0; i < numberTaps_; i++) {
			output += data_[ptr_] * coef_[i];
			ptr_ = increment(ptr_, numberTaps_);
		}

		/*  DECREMENT THE DATA POINTER READY FOR NEXT CALL  */
		ptr_ = decrement(ptr_, numberTaps_);

		/*  RETURN THE OUTPUT VALUE  */
		return output;
	} else {
		/*  PUT INPUT SAMPLE INTO DATA BUFFER  */
		data_[ptr_] = input;

		/*  ADJUST THE DATA POINTER, READY FOR NEXT CALL  */
		ptr_ = decrement(ptr_, numberTaps_);

		return 0.0;
	}
}
Exemplo n.º 4
0
    /**
     * @brief push_front
     */
    void push_front(const T& val)
    {
        assert(!full());

        if(head == c.end())
            head = decrement(head);

        *head = val;
        head = decrement(head);
    }
Exemplo n.º 5
0
void CompilerStubs::generate_compiler_new_object() {
  comment_section("Compiler new object (any size)");
  comment("Register edx holds the instance size, register ebx holds the prototypical near of the instance class");
  Label slow_case;
  entry("compiler_new_object");

  comment("Get _inline_allocation_top");
  movl(eax, Address(Constant("_inline_allocation_top")));

  comment("Compute new top");
  leal(ecx, Address(eax, edx, times_1));

  if (GenerateDebugAssembly) {
    comment("Check ExcessiveGC");
    testl(Address(Constant("ExcessiveGC")), Constant(0));
    jcc(not_zero, Constant(slow_case));
  }

  comment("Compare against _inline_allocation_end");
  cmpl(ecx, Address(Constant("_inline_allocation_end")));
  jcc(above, Constant(slow_case));

  comment("Allocation succeeded, set _inline_allocation_top");
  movl(Address(Constant("_inline_allocation_top")), ecx);

  comment("Set prototypical near in object; no need for write barrier");
  movl(Address(eax), ebx);

  comment("Compute remaining size");
  decrement(edx, oopSize);

  comment("One-word object?");
  Label init_done;
  jcc(zero, Constant(init_done));

  comment("Zero object fields");
  xorl(ecx, ecx);
  Label init_loop;
  bind(init_loop);
  movl(Address(eax, edx, times_1), ecx);
  decrement(edx, oopSize);
  jcc(not_zero, Constant(init_loop));
  bind(init_done);

  comment("The newly allocated object is in register eax");
  ret();

  comment("Slow case - call the VM runtime system");
  bind(slow_case);
  leal(eax, Address(Constant("newobject")));
  goto_shared_call_vm(T_OBJECT);

  entry_end(); // compiler_new_object
}
Exemplo n.º 6
0
FFEvent* TimeTable::getUpcomingEvent(){
	FFEvent* upEvent = head;
	if ( size() > 1 ) {
		setHead(head->getNext());
		decrement();
	} else if ( size() == 1 ) {
		// this is the only event left
		decrement();
	} else {
		// no events left to be treated (size=0)
		cout << "ForeFire simulation ended with no more event to be treated" << endl;
		upEvent = 0;
	}
	return upEvent;
}
Exemplo n.º 7
0
int main()
{
    int i = 0;
    std::string str = "asdf";

    decrement(i);
    decrement(str);

    std::cout << i << " "<<str<<std::endl;

    F foo;
    foo.decrement(i);
    foo.decrement(str);
    std::cout << i << " "<<str<<std::endl;
}
Exemplo n.º 8
0
 void pop_back()
 {
     MGBASE_ASSERT(!empty());
     --size_;
     
     decrement(&last_);
 }
Exemplo n.º 9
0
		void advance(difference_type dist)
		{
			for (; dist != 0; --dist)
				{
					decrement();
				}
		}
Exemplo n.º 10
0
void Demo::DepthZoom::on_incNear_pressed() {
    float z = increment(mN);
    float f = decrement(mF - mN);
    mN += z < f ? z : f;
    mUI->nearValue->setText(QString("%1").arg((double) mN, 0, 'f', 2, QChar('0')));
    emit valuesChanged(mN, mF);
}
Exemplo n.º 11
0
void Task< Kokkos::Serial , void >::schedule_dependence_reserve(int n)
{
  if ( STATE_CONSTRUCTING != m_state && STATE_EXECUTING != m_state ) {
    throw std::runtime_error(std::string("Kokkos::Impl::Task spawn or respawn state error"));
  }

  m_state = STATE_WAITING ;

  for ( int i = 0 ; i < m_dep_count ; ++i ) {
    decrement( m_dep[i] );
    m_dep[i] = 0 ;
  }

  if ( DEP_COUNT_BASE < n && m_dep_alloc < n ) {
    if ( m_dep_alloc ) {
      // Thread safety and scalability of 'free' ?
      free( m_dep );
    }
    m_dep_alloc = n ;
    // Thread safety and scalability of 'malloc' ?
    m_dep = reinterpret_cast<Task**>( malloc( n * sizeof(Task*) ) );

    for ( int i = 0 ; i < m_dep_alloc ; ++i ) { m_dep[i] = 0 ; }
  }

  m_dep_count = n ;
}
Exemplo n.º 12
0
long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal )
{
    if ( ordinal == firstInList )  {
        return -1;
    }
    return decrement(ordinal);
}
// Arbitrary-size push function
unsigned int pushToBuffer(buffer_t *b, void *d, unsigned int l) {
    unsigned int elementIndex, byteIndex;
    
    // Loop through all elements
    for (elementIndex = 0; elementIndex < l; elementIndex++) {

        // Loop through all bytes of each element
        for (byteIndex = 0; byteIndex < b->width; byteIndex++) {
        
            // Only push to buffer if it is not full or overwriting is allowed
            if ( (!isBufferFull(b)) || (b->behavior.bits.overwrite) ) {
                pushByte(b, *( (unsigned char*)(d + elementIndex * (b->width) + byteIndex) ));
            }
            
            // If buffer is full, return a count of those elments not pushed
            else {
                
                // Pop all bytes of incomplete elements
                // -This should never run, but added just in case
                unsigned int failedbytes;
                for (failedbytes = byteIndex; failedbytes > 0; failedbytes--) {
                   
                    // If it is a queue pop comes from tail, so decrement head
                    decrement(b, &(b->head));
                }
                
                // Return a count of failed push operations
                // -Include partial pushes in count
                return l - elementIndex;
            }
        }
    }
    return 0;
}
Exemplo n.º 14
0
FIT_TEST_CASE()
{
    constexpr auto f = fit::compose(increment(), decrement());
    static_assert(std::is_empty<decltype(f)>::value, "Compose function not empty");
    int r = f(3);
    FIT_TEST_CHECK(r == 3);
    FIT_STATIC_TEST_CHECK(f(3) == 3);
}
Exemplo n.º 15
0
void CGUINumberControl::processLogic()
{
    GsPointingState &pointingState = gPointDevice.mPointingState;

    const bool hasPoint = mRect.HasPoint(pointingState.mPos);
    const bool bDown = (pointingState.mActionButton>0);

    const float xMid = mRect.x+(mRect.w/2.0f);

    mReleased = false;

    mDecSel = false;
    mIncSel = false;

    Vector2D<float> mousePos = pointingState.mPos;

    if( mousePos.x < xMid )
        mDecSel = true;
    else if( mousePos.x > xMid )
        mIncSel = true;


    if(!bDown && mPressed)
    {
        mPressed = false;

        if(hasPoint)
        {
            mReleased = true;
        }
    }

    if(!bDown || mPressed)
    {
        mHovered = hasPoint;
    }

    if(mHovered && bDown)
    {
        mPressed = true;

        if( mDecSel )
        {
            // Cycle through the values -> go one value down
            if( mValue > mStartValue )
                decrement();
        }
        else if( mIncSel )
        {
            // Cycle through the values -> go one value up
            if( mValue < mEndValue )
                increment();
        }

        mMustRedraw = true;
    }

}
Exemplo n.º 16
0
long IOPMchangeNoteList::latestChange ( void )
{
    if ( firstUnused == firstInList ) {
        return -1;
    }
    else {
        return decrement(firstUnused);
    }
}
Exemplo n.º 17
0
////////////////////////////////////////////////////////////////////////////////
// Do 'bars[epoch] = Bar' for every bar that may appear on a chart.
void Chart::generateBars ()
{
  Bar bar;

  // Determine the last bar date.
  Date cursor;
  switch (period)
  {
  case 'D': cursor = Date ().startOfDay ();   break;
  case 'W': cursor = Date ().startOfWeek ();  break;
  case 'M': cursor = Date ().startOfMonth (); break;
  }

  // Iterate and determine all the other bar dates.
  char str[12];
  for (int i = 0; i < estimated_bars; ++i)
  {
    // Create the major and minor labels.
    switch (period)
    {
    case 'D': // month/day
      {
        std::string month = Date::monthName (cursor.month ());
        bar.major_label = month.substr (0, 3);

        sprintf (str, "%02d", cursor.day ());
        bar.minor_label = str;
      }
      break;

    case 'W': // year/week
      sprintf (str, "%d", cursor.year ());
      bar.major_label = str;

      sprintf (str, "%02d", cursor.weekOfYear (0));
      bar.minor_label = str;
      break;

    case 'M': // year/month
      sprintf (str, "%d", cursor.year ());
      bar.major_label = str;

      sprintf (str, "%02d", cursor.month ());
      bar.minor_label = str;
      break;
    }

    bar.offset = i;
    bars[cursor.toEpoch ()] = bar;

    // Record the earliest date, for use as a cutoff when scanning data.
    earliest = cursor;

    // Move to the previous period.
    cursor = decrement (cursor);
  }
}
Exemplo n.º 18
0
void
shared_count::release_shared()
{
    if (decrement(shared_owners_) == -1)
    {
        on_zero_shared();
        delete this;
    }
}
Exemplo n.º 19
0
 void push_front(const T& val)
 {
     MGBASE_ASSERT(!full());
     ++size_;
     
     decrement(&first_);
     
     // Copy the value after decrement.
     data()[first_] = val;
 }
Exemplo n.º 20
0
	Ptr<T>& operator=(const Ptr<Y>& other)
	{
	    if(this != &other) {
		decrement();
		if(fRef = other.fRef) {
		    fRef->AddReference();
		}
	    }
	    return *this;
	}
Exemplo n.º 21
0
void WeaponUpdater::update(float dt)
{
    const u32 dtMs = static_cast<u32>(dt * 1000.0f);

    for (auto& it : _modules)
    {
        WeaponModule& moduleInstance = it.second;
        moduleInstance.cooldownMs = decrement(moduleInstance.cooldownMs, dtMs);
    }
}
Exemplo n.º 22
0
int	main(int argc, char *argv[]) {
	char	op,*buf;
	int	shmid;
	key_t	key=KEYVALUE;

	if (argc!=2) usage(argv[0]);
	op=argv[1][0];
	if (op!='+' && op!='-' && op!='s') usage(argv[0]);

	/* create */
	shmid=shmget(	key,
			BUFSIZE,
			0600 | IPC_CREAT
		    );
	if (shmid==-1) { perror("shmget"); exit(-1); }

	/* attach */
	buf=shmat(	shmid,
			(void *)NULL,
			0
		 );
	if (buf==(void *)-1) { perror("shmat"); exit(-1); }

	/* use it */
	while (1) {
		switch(op) {
		case	'+':
			increment(buf, BUFSIZE);
			fprintf(stderr,"+");
			break;
		case	'-':
			decrement(buf, BUFSIZE);
			fprintf(stderr,"-");
			break;
		case	's':
			fprintf(stderr, "[Sum=%d]\r", sum(buf, BUFSIZE));
			break;
		default:
			break;
		}
	}

	/* detach */
	if (shmdt(buf)==-1) { perror("shmdt"); exit(-1); }

	if (op=='s') {	/* the 'sum' one should destroy the share mem */
		if (shmctl(	shmid,
				IPC_RMID,
				0
		      )==-1) {
			perror("shmctl:destroy");
			exit(-1);
		}
	}
}
Exemplo n.º 23
0
void animation_previous()
{
    stop_animation();
    if (current_animation == animation_type_o_matic)
        current_animation = animation_LAST;
    current_animation = (animation_names)decrement(current_animation, 1, 0, animation_LAST);
    dprintf("animation_previous: %u\n", current_animation);

    set_animation(current_animation);
    start_animation();
}
Exemplo n.º 24
0
void GuiRangeSliderBase::keyboardEdit(int key)
{
    if (key == OF_KEY_LEFT)
    {
        decrement();
    }
    else if (key == OF_KEY_RIGHT)
    {
        increment();
    }
}
Exemplo n.º 25
0
void Task< Kokkos::Serial , void >::task_wait( Task< Kokkos::Serial , void > * )
{
  while ( s_ready ) {

    // Remove this task from the ready list

    // Task * task ;
    // while ( ! CAS( & s_ready , task = s_ready , s_ready->m_next ) );

    Task * const task = s_ready ;
    s_ready = task->m_next ;

    task->m_next = 0 ;

    // precondition: task->m_state = STATE_WAITING
    // precondition: task->m_dep[i]->m_state == STATE_COMPLETE  for all i
    // precondition: does not exist T such that T->m_wait = task
    // precondition: does not exist T such that T->m_next = task

    task->m_state = STATE_EXECUTING ;

    (*task->m_apply)( task );

    if ( task->m_state == STATE_EXECUTING ) {
      // task did not respawn itself
      task->m_state = STATE_COMPLETE ;

      // release dependences:
      while ( task->m_dep_count ) {
        const int i = --( task->m_dep_count );
        decrement( task->m_dep[i] );
        task->m_dep[i] = 0 ;
      }

      // Stop other tasks from adding themselves to 'task->m_wait' ;

      Task * x ;
      // CAS( & task->m_wait , x = task->m_wait , s_denied );
      x = task->m_wait ; task->m_wait = (Task*) s_denied ;

      // update tasks waiting on this task
      while ( x ) {
        Task * const next = x->m_next ;

        x->m_next = 0 ;

        x->schedule();

        x = next ;
      }
    }
  }
}
Exemplo n.º 26
0
 void
 decrement(C<sizeof...(Bs)>)
 {
     auto constexpr I = sizeof...(Bs);
     if(n_ == I)
     {
         --n_;
         new(buf_.data()) iter_t<I-1>{
             std::get<I-1>(*bs_).end()};
     }
     decrement(C<I-1>{});
 }
Exemplo n.º 27
0
 static void restore(
   ordered_index_node_impl* x,ordered_index_node_impl* position,
   ordered_index_node_impl* header)
 {
   if(position->left()==0||position->left()==header){
     link(x,to_left,position,header);
   }
   else{
     decrement(position);
     link(x,to_right,position,header);
   }
 }
Exemplo n.º 28
0
void DamageUpdater::update(float /*dt*/)
{
    for (auto& it : _modules)
    {
        auto& moduleInstance = it.second;
        moduleInstance.health = decrement(moduleInstance.health, moduleInstance.damages);
        moduleInstance.damages = 0;

        if (moduleInstance.health == 0)
            _worldUpdater->notifyRemoveEntity(it.first);
    }
}
Exemplo n.º 29
0
int main(int argc, char *argv[])
{
  int c[] = {0,9,3,6,1,1,6};

  for( int i = 0; i < 70; i++ ) {
    decrement( c );
    printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",i,c[0],c[1],c[2],c[3],c[4],c[5],c[6]);
    sleep(1);
  }

  return 0;
}
Exemplo n.º 30
0
bool TopicCounts::findAndDecrement(topic_t topic) {
    topic_t* endItem = (topic_t*) (items + length);
    topic_t* beg = (topic_t*) items;
    topic_t* ptr = beg;
    for (topic_t* ind = beg; ind < endItem; ind = ind + 2) {
        if (*ind == topic) {
            decrement((ind - beg) / 2, &ptr);
            return true;
        }
    }
    return false;
}