Ejemplo n.º 1
0
void erase_ball(float crow, float ccol, float radius) {
  for (int r = floor(crow) - radius - 1; r <= ceil(crow) + radius + 1; r++) {
    for (int c = floor(ccol) - radius - 1; c <= ceil(ccol) + radius + 1; c++) {
      if (r >= 0 && r < NUM_ROWS) {
        int index = pixel_index(r, modulo(c, NUM_COLUMNS));
        set_rgb(pixels, index, 0, 0, 0);
      }
    }
  }
}
Ejemplo n.º 2
0
int main(){
	//need to use double notation here otherwise we get extremely weird printouts !NaN
	double num1= 1.5;
	double numneg1= -1.5;
	double num2= 1;
	double numneg2= -1;
	double num3= 69;
	double num4= 100;
	double numneg4= -100;
	double num5= 3.45;
	double num0= 0;
	
	printf("Absolute:\n");
    printf("abs(1.5) = %16.8lf\n", absolute(num1));
    printf("abs(-1.5) = %16.8lf\n", absolute(numneg1));
    printf("abs(69) = %16.8lf\n", absolute(num3));
    printf("abs(-100) = %16.8lf\n\n", absolute(numneg4));

	printf("Modulo(remainder of x/y where(x,y)):\n");
	printf( "modulo(0, 1) = %16.8lf\n", modulo(num0, num2));	//returns 0
	printf( "modulo(1, 0) = %16.8lf\n", modulo(num2, num0));	//returns NaN
    printf( "modulo(1, 1) = %16.8lf\n", modulo(num2, num2));
    printf( "modulo(-1.5, 1) = %16.8lf\n", modulo(numneg1, num2));	//should be positive?!
	printf( "modulo(-1, -1.5) = %16.8lf\n", modulo(numneg2, numneg1));
	printf( "modulo(100, 69) = %16.8lf\n", modulo(num4, num3));
	printf( "modulo(3.45, 1.5) = %16.8lf\n\n", modulo(num5, num1));

	//not allowed to pass in negative values, so return 0
    printf("Factorial:\n");
	printf( "1! = %16.8lf\n", factorial(1));
	printf( "-1! = %16.8lf\n", factorial(-1));
	printf( "3! = %16.8lf\n", factorial(3));
	printf( "-3! = %16.8lf\n", factorial(-3));
	printf( "5! = %16.8lf\n", factorial(5));
	printf( "10! = %16.8lf\n\n", factorial(10));
	//printf( "1.5! = %16.8lf\n", factorial(1.5));	//no testing for float exponents because unsigned int is passed in
	
    printf("Power:\n");		//no testing for float exponents because unsigned int is passed in
	printf("%d ^ %d = %16.8lf\n", 0, 2, power(0,2));
    printf("%d ^ %d = %16.8lf\n", 1, 1, power(1,1));
    printf("%d ^ %d = %16.8lf\n", 3, 3, power(3.0,3.0));
    printf("%d ^ %d = %16.8lf\n", -1, 1, power(-1,1));
    printf("%d ^ %d = %16.8lf\n", -4, 2, power(-4,2));
	printf("%d ^ %d = %16.8lf\n\n", -1, -1, power(-1,-1));
	//negative exponents and negative bases have not been fully worked out yet, really need to do additional testing(test cases)
	
	//test cases even though didn't finish sine
    printf( "sine(0): %16.8lf\n", sine(0));
    printf( "sine(pi/2): %16.8lf\n", sine(M_PI/2));
    printf( "sine(pi/3): %16.8lf\n", sine(M_PI/3));
    printf( "sine(pi/4): %16.8lf\n", sine(M_PI/4));
    printf( "sine(pi/6): %16.8lf\n", sine(M_PI/6));
    printf( "sine(pi): %16.8lf\n", sine(M_PI));
	printf( "sine(-pi): %16.8lf\n", sine(-M_PI));
	printf( "sine(-1.5): %16.8lf\n\n", sine(-1.5));

    return 0;
}
Ejemplo n.º 3
0
// Greenwich Mean Sidereal Time
double gmst(double mjd)
{
  double t,gmst;

  t=(mjd-51544.5)/36525.0;

  gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);

  return gmst;
}
Ejemplo n.º 4
0
void leggi_matrice (int dim,matrice a)
    {int i,j;float p,som;
     printf ("\nInserisci i coefficienti della matrice:\n");
     for (i=1;i<=dim;i++)
         { for (j=1;j<=dim;j++)
                  {printf ("a[%d][%d]=",i,j); scanf ("%f",&a[i][j]);}}   
     som=0;
     for(i=1;i<=dim;i++)
         {for(j=1;j<=dim;j++)
                 {p=a[i][j]; som=som+p; 
          if(modulo(a[i][i])<modulo(som)) 
                {printf("\n ATTENZIONE!!!");
                 printf("la matrice non e' dominante diagonale nella %d riga",i);
                 printf("\n riprova\n"); 
                 for (i=1;i<=dim;i++)
                     for (j=1;j<=dim;j++)
                        {printf ("a[%d][%d]=",i,j);scanf ("%f",&a[i][j]);}}
          som=0;}}
     return;}
Ejemplo n.º 5
0
void variacoes(int framesPorSegundo, int tempoMaximo, int numeroDePessoas)
{
	int linha, coluna, cont = 0;
	double veloc, vMIN = 10, vMAX = 0, vMedia = 0,deltaT;
	char tipo;
	vetor v;
	celula ** mar;
	clock_t inicio, anterior, var;
	srand(time(NULL));
	
	mar = iniciaMar(30, 120);
	mar = gera_pessoas(mar, 40, 0, 30, 120);

        inicio = clock();
        anterior = 0;
        
        while(clock() - inicio < tempoMaximo*CLOCKS_PER_SEC) 
        {
               var = clock() - anterior;

                if(var > CLOCKS_PER_SEC/framesPorSegundo )
                {  
                        deltaT = (double)var/(double)CLOCKS_PER_SEC; 
      
        	        atualizaMar(mar, 30, 120, deltaT);
			for( linha = 0; linha < 30; linha++)
			{
				for(coluna = 0; coluna < 120 ; coluna++)
				{
					tipo = mar[linha][coluna].categoria;
				
					if(tipo == 'p')
                		        {
                		               v = mar[linha][coluna].f->p.vel;
                		               veloc = modulo(v);  

					       if(veloc < vMIN)
							vMIN = veloc;
					       else if(veloc > vMAX)
							vMAX = veloc;				
					 
					 vMedia += veloc;
						 cont++;
                		        }
	
				}
			}
	                anterior = clock();
                }        

        }
	vMedia = vMedia/cont;
	printf("\nt: %d Vmax: %f, Vmin: %f, Vmedia: %f\n\n", tempoMaximo,vMAX,vMIN,vMedia);
 	liberaMar(mar, 30, 120);
}
Ejemplo n.º 6
0
// result = (a * b )% m = (a % m) * (b % m) % m
int modMultMagic(bigint a, bigint b, bigint m, bigint *result){
  dblbigint tmp={0};
  bigint a_tmp={0}, b_tmp={0};

  printf("a = ");
  writeBigint(stdout,a);
  printf("\n");
  // a % m
  modulo(a, m, &a_tmp);   
  printf("a mod m = ");
  writeBigint(stdout,a_tmp);
  printf("\n");

  printf("b = ");
  writeBigint(stdout,b);
  printf("\n");
  // b % m
  modulo(b, m, &b_tmp);
  printf("b mod m = ");
  writeBigint(stdout,b_tmp);
  printf("\n");

  mult(a_tmp, b_tmp, &tmp);
  printf("(a mod m)*(b mod m)= ");
  writeDblbigint(stdout,tmp);
  printf("\n");

  /*for( int i = 0; i < NCHUNKS; i ++){
    result[0].data[i] = (uint16_t)tmp.data[i];
   }
  writeBigint(stdout,result[0]);
  */
  dblmodulo(tmp, m, result);
  printf("(a mod m)*(b mod m) mod m= ");
  writeBigint(stdout,result[0]);
  printf("\n");

  int x=25, y=5;
  //printf("%d/%d=%d\n", x,y, divide(x,y)); 

  return SUCCESS;
}
Ejemplo n.º 7
0
static void b43_destroy_dmaring(struct b43_dmaring *ring,
				const char *ringname)
{
	if (!ring)
		return;

#ifdef CONFIG_B43_DEBUG
	{
		
		u64 failed_packets = ring->nr_failed_tx_packets;
		u64 succeed_packets = ring->nr_succeed_tx_packets;
		u64 nr_packets = failed_packets + succeed_packets;
		u64 permille_failed = 0, average_tries = 0;

		if (nr_packets)
			permille_failed = divide(failed_packets * 1000, nr_packets);
		if (nr_packets)
			average_tries = divide(ring->nr_total_packet_tries * 100, nr_packets);

		b43dbg(ring->dev->wl, "DMA-%u %s: "
		       "Used slots %d/%d, Failed frames %llu/%llu = %llu.%01llu%%, "
		       "Average tries %llu.%02llu\n",
		       (unsigned int)(ring->type), ringname,
		       ring->max_used_slots,
		       ring->nr_slots,
		       (unsigned long long)failed_packets,
		       (unsigned long long)nr_packets,
		       (unsigned long long)divide(permille_failed, 10),
		       (unsigned long long)modulo(permille_failed, 10),
		       (unsigned long long)divide(average_tries, 100),
		       (unsigned long long)modulo(average_tries, 100));
	}
#endif 

	dmacontroller_cleanup(ring);
	free_all_descbuffers(ring);
	free_ringmemory(ring);

	kfree(ring->txhdr_cache);
	kfree(ring->meta);
	kfree(ring);
}
Ejemplo n.º 8
0
	bool getSamplePosition(const PositionSamplingRecord &pRec,
			const DirectionSamplingRecord &dRec, Point2 &samplePosition) const {
		Vector d = normalize(m_worldTransform->eval(pRec.time).inverse()(dRec.d));

		samplePosition = Point2(
			modulo(std::atan2(d.x, -d.z) * INV_TWOPI, (Float) 1) * m_resolution.x,
			math::safe_acos(d.y) * INV_PI * m_resolution.y
		);

		return true;
	}
Ejemplo n.º 9
0
	Square& Board::get(const Coordinates& coordinates)
	{
		Coordinates local_coords = {modulo(coordinates.x(), NM_CHUNK_SIZE), modulo(coordinates.y(), NM_CHUNK_SIZE)};

		Coordinates chunk_coordinates = {static_cast<int>(std::floor(coordinates.x() / (double)NM_CHUNK_SIZE)),
										 static_cast<int>(std::floor(coordinates.y() / (double)NM_CHUNK_SIZE))};

		auto chunk_iterator = chunks.find(chunk_coordinates);
		if (chunk_iterator == chunks.end())
		{
			if (client_mode)
				return Chunk::CHUNK_EMPTY.get(local_coords);
			// The chunk does not exist, so we generate it.
			BOOST_LOG_TRIVIAL(info) << "[board] generating chunk at (" << chunk_coordinates.x()
					  << ", " << chunk_coordinates.y() << ")";
			chunks[chunk_coordinates] = chunkGenerator.generate();
		}

		return chunks[chunk_coordinates].get(local_coords);
	}
int main(int argc, char *argv[])
{
    int caseNumber;
    scanf("%d",&caseNumber);
    while(caseNumber--)
    {
        input();
        multiplication();
        modulo();
        output();
    }
}
bool checkprime(long long n,int iterations){

    if(n==1) return false;
    for(int i=0;i<iterations;++i){

         long long a=rand()%(n-1)+1;
         
         if(modulo(a,n-1,n)!=1) return false;

    }
     return true;
}
Ejemplo n.º 12
0
float lambda (int dim,matrice a)
    {int i,j;float c,som,max;vettore tot;
     som=0;
     for(i=1;i<=dim;i++)
         {for(j=1;j<=dim;j++)
             {c=a[i][j]/a[i][i];
             som=som+c;}
          tot[i]=modulo(som-1);}
     max=tot[1];
     for(i=1;i<=dim;i++)
          if(tot[1]>max) tot[i]=max;
     return(max);}
Ejemplo n.º 13
0
void do_op(char C)
{
  switch(C)
  {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9': push(C-'0'); break;
    case '+': addition(); break;
    case '-': subtraction(); break;
    case '*': multiplication(); break;
    case '/': division(); break;
    case '%': modulo(); break;
    case '^': north(); break;
    case '>': east(); break;
    case 'V':
    case 'v': south(); break;
    case '<': west(); break;
    case '?': spin(); break;
    case '!': lnot(); break;
    case '`': gt(); break;
    case '_': hif(); break;
    case '|': vif(); break;
    case '"': tsm(); break;
    case ':': dup(); break;
    case '\\': swap(); break;
    case '$': chomp(); break;
    case '#': jump(); break;
    case 'p': put(); break;
    case 'g': get(); break;
    case 'H': gate(); break;
    case '.': print_i(); break;
    case ',': print_c(); break;
    case '&': input_i(); break;
    case '~': input_c(); break;
    case '@': hacf(); break;
    case '{': left_b(); break;
    case '}': right_b(); break;
    case '[': carry_l(); break;
    case ']': carry_r(); break;
    case ';': empty(); break;
    case 'O': portal_o(); break;
    case 'B': portal_b(); break;
    default: /* DO NOTHING! */ break;
  }
}
//Verifica si hay puntos colineales y los borra, dejando solo el mas lejano 
// (la lista debe venir ordenada en forma polar)
void eliminarColineales(std::list<Point2D> &Q){
  std::list<Point2D>::iterator p = Q.begin();
  std::list<Point2D>::iterator q = p;
  q++;
  while(p != Q.end() and q != Q.end()){
    while(p != Q.end() and q != Q.end() and compareEqualAngle(*p, *q)){
      float modp = modulo(*p);
      float modq = modulo(*q);
      if(modp < modq){
          p = Q.erase(p);
          q++;
      } 
      else {
          q = Q.erase(q);
          p = q;
          q++;
      }
    }
    if(q == Q.end() or p == Q.end()) break;
    p++; q++;
  }
}
Ejemplo n.º 15
0
/* Algorithm: Modular Power: x^e(mod n) using 
   the repeated square-and-multiply algorithm */
long int ModPower(long int x, long int e, long int n)
{
	// To calculate y:=x^e(mod n).
        //long y;
        long int y;
	long int t;
        int i;
	int BitLength_e;
	char b[STACK_SIZE];

        //printf("e(decimal) = %ld\n",e);
	decimal_to_binary(e,b);
	if(print_flag)
	 printf("b = %s\n", b);
	BitLength_e = strlen(b);
        
	y = x;

	reverse_string(b);

	for(i = BitLength_e - 2; i >= 0 ; i--)
	{
		if(print_flag)
		 printf("\nb[%d]=%c", i, b[i]);
		if(b[i] == '0')
			t = 1;
		else t = x;
                y = y * y;
                y = modulo (y, n);

		y = y*t;
                y = modulo (y, n);
	}

        
	return y;
        
} 
Ejemplo n.º 16
0
int makeHexadecagon(coord_t* si, coord_t* id, hexadecagon_t* hexa, filtro_gestos_in_imagen_t* image)
{
  int up,down,left,right,upi,downi,lefti,righti,anch,alt,negroUL,negroDL,negroUR,negroDR,h;
  double diagonal;
  makeHexadecagonAux(si,id,hexa,image,0);
  makeHexadecagonAux(si,id,hexa,image,4);
  makeHexadecagonAux(si,id,hexa,image,8);
  diagonal= modulo(si->m_x,si->m_y,id->m_x,id->m_y);
  negroUL=negroDL=negroUR=negroDR=0;
  up= si->m_y; left= si->m_x;
  down= id->m_y; right= id->m_x;
  anch= right-left; alt= down-up;

  h=1; lefti=upi=0;
  while(!negroUL && upi<=alt && lefti<=anch)
    if(!image->m_imagen[(up*image->m_bytes*image->m_ancho)+left])negroUL=1;
    else{up++;upi++;left+=floor((h*anch)/alt);h++;lefti+=floor((h*anch)/alt);}
  hexa->m_list[12]= (double)(modulo(lefti,upi,0,0)*100)/diagonal;

  up=si->m_y; h=1; righti=upi=0;
  while(!negroUR && upi<=alt && righti<=anch)
    if(!image->m_imagen[(up*image->m_bytes*image->m_ancho)+right])negroUR=1;
    else{up++;upi++;right-=floor((h*anch)/alt);h++;righti+=floor((h*anch)/alt);}
  hexa->m_list[13]= (double)(modulo(righti,upi,0,0)*100)/diagonal;

  left=si->m_x; h=1; lefti=downi=0;
  while(!negroDL && downi<=alt && lefti<=anch)
    if(!image->m_imagen[(down*image->m_bytes*image->m_ancho)+left])negroDL=1;
    else{down--;downi++;left+=floor((h*anch)/alt);h++;lefti+=floor((h*anch)/alt);}
  hexa->m_list[14]= (double)(modulo(lefti,downi,0,0)*100)/diagonal;

  right=id->m_x; down=id->m_y; h=1; righti=downi=0;
  while(!negroDR && downi<=alt && righti<=anch)
    if(!image->m_imagen[(down*image->m_bytes*image->m_ancho)+right])negroDR=1;
    else{down--;downi++;right-=floor((h*anch)/alt);h++;righti+=floor((h*anch)/alt);}
  hexa->m_list[15]= (double)(modulo(righti,downi,0,0)*100)/diagonal;
  return 0;
}
Ejemplo n.º 17
0
int main()
{
  push(5);
  push(5);
  addition();
  cout << "pushed 5, 5, and added, top now " << pop() << endl;

  push(5);
  push(4);
  subtraction();
  cout << "pushed 5, 5, and subtracted, top now " << pop() << endl;

  push(2);
  push(5);
  multiplication();
  cout << "pushed 2, 5 and multiplied, top now " << pop() << endl;
  
  push(9);
  push(3);
  division();
  cout << "pushed 9, 3 and divided, top now " << pop() << endl;

  push(9);
  push(0);
  division();
  cout << "pushed 9, 0 and divided, top now " << pop() << endl;

  push(9);
  push(3);
  modulo();
  cout << "pushed 9, 3 and modulosed, top now " << pop() << endl;

  push(9);
  push(0);
  modulo();
  cout << "pushed 9, 0 and modulosed, top now " << pop() << endl;

}
Ejemplo n.º 18
0
bool Fermat( long long p,int iterations){
    if(p == 1){ // 1 isn't prime
        return false;
    }
    for(int i=0;i<iterations;i++){
        // choose a random integer between 1 and p-1 ( inclusive )
         long long a = rand()%(p-1)+1; 
        // modulo is the function we developed above for modular exponentiation.
        if(modulo(a,p-1,p) != 1){ 
            return false; /* p is definitely composite */
        }
    }
    return true; /* p is probably prime */
}
Ejemplo n.º 19
0
/**	void paralelepipedo(float x0, float y0, float z0, float x1, float y1, float z1,  float a, float b)

Crea un paralelepipedo con centro de las bases en
x0,y0,z0 y x1,y1,z1, y tamanyo de la base axb.

**/
void paralelepipedo(float x0, float y0, float z0, 
		    float x1, float y1, float z1, 
		    float a, float b)
{
float m;

m= modulo(x1-x0,y1-y0,z1-z0);
glPushMatrix();
	glTranslatef(x0,y0,z0);
	glRotatef(-180.0*atan2((z1-z0),(x1-x0))/M_PI,0.0,1.0,0.0);
	glRotatef(180.0*atan2((y1-y0),sqrt((x1-x0)*(x1-x0)+(z1-z0)*(z1-z0)))/M_PI-90,0.0,0.0,1.0);
	caja(a,m,b);
glPopMatrix();
}	
Ejemplo n.º 20
0
	void Board::clear_at(int x, int y)
	{
		Coordinates local_coords = {modulo(x, NM_CHUNK_SIZE), modulo(y, NM_CHUNK_SIZE)};

		Coordinates chunk_coordinates = nm::utils::to_chunk_coordinates({x, y});

		BOOST_LOG_TRIVIAL(info) << "Clearing around (X: " << local_coords.x() << " Y: " << local_coords.y() << "), "
			<< "Chunk " << chunk_coordinates.x() << ", " << chunk_coordinates.y() << ".";

		std::optional<Chunk* const> maybeChunk = this->get_chunk(chunk_coordinates);
		Chunk* const chunk = maybeChunk ? *maybeChunk : &regenerate_chunk(chunk_coordinates);

		static int around_offsets[3] = {-1, 0, 1};

		for (auto&& xoff : around_offsets)
		{
			for (auto&& yoff : around_offsets)
			{
				Square &around = chunk->get(local_coords.x() + xoff, local_coords.y() + yoff);
				around.is_mine = false;
			}
		}
	}
Ejemplo n.º 21
0
Spectrum MIPMap::getTexel(int level, int x, int y) const {
	int levelWidth = m_levelWidth[level];
	int levelHeight = m_levelHeight[level];

	if (x <= 0 || y < 0 || x >= levelWidth || y >= levelHeight) {
		switch (m_wrapMode) {
			case ERepeat:
				x = modulo(x, levelWidth);
				y = modulo(y, levelHeight);
				break;
			case EClamp:
				x = clamp(x, 0, levelWidth - 1);
				y = clamp(y, 0, levelHeight - 1);
				break;
			case EBlack:
				return Spectrum(0.0f);
			case EWhite:
				return Spectrum(1.0f);
		}
	}

	return m_pyramid[level][x + levelWidth*y];
}
Ejemplo n.º 22
0
int play_controller::find_last_visible_team() const
{
    assert(current_side() <= int(gamestate().board_.teams().size()));
    const int num_teams = gamestate().board_.teams().size();
    const bool is_observer = this->is_observer();

    for(int i = 0; i < num_teams; i++) {
        const int team_num = modulo(current_side() - i, num_teams, 1);
        if(is_team_visible(team_num, is_observer)) {
            return team_num;
        }
    }
    return 0;
}
Ejemplo n.º 23
0
 DEVICE
 inline void operator()(int idx) {
     const auto &d_tex = d_roughness_texs[idx];
     auto mid = d_tex.material_id;
     auto xi = d_tex.xi;
     auto yi = d_tex.yi;
     auto texels = d_materials[mid].roughness.texels;
     if (xi < 0) {
         texels[0] += d_tex.t000;
     } else {
         auto w = d_materials[mid].roughness.width;
         auto h = d_materials[mid].roughness.height;
         auto num_levels = d_materials[mid].roughness.num_levels;
         auto xi0 = xi;
         auto xi1 = modulo(xi + 1, w);
         auto yi0 = yi;
         auto yi1 = modulo(yi + 1, h);
         // Different DTexture may overlap, so we need to use atomic updates
         // The probability of collision should be small in SIMD regime though
         auto level = d_tex.li;
         if (d_tex.li == -1) {
             level = 0;
         }
         auto lower_texels = texels + level * w * h;
         atomic_add(lower_texels[yi0 * w + xi0], d_tex.t000);
         atomic_add(lower_texels[yi0 * w + xi1], d_tex.t100);
         atomic_add(lower_texels[yi1 * w + xi0], d_tex.t010);
         atomic_add(lower_texels[yi1 * w + xi1], d_tex.t110);
         if (d_tex.li >= 0 && d_tex.li < num_levels - 1) {
             auto higher_texels = texels + (level + 1) * w * h;
             atomic_add(higher_texels[yi0 * w + xi0], d_tex.t001);
             atomic_add(higher_texels[yi0 * w + xi1], d_tex.t101);
             atomic_add(higher_texels[yi1 * w + xi0], d_tex.t011);
             atomic_add(higher_texels[yi1 * w + xi1], d_tex.t111);
         }
     }
 }
int main()
{
    int i,j,t,n,lim,ts,nc;
    flag=false;
    int primes[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709};
    //scanf("%d",&t);
    t=inp();
    while(t--)
    {
        //scanf("%d",&n);
        n=inp();
        lim=sqrt(n);nc=n;
        int ndiv=1,ans;
        for(i=0;i<=125 && primes[i]<=701 && primes[i]<=lim;i++)
        {
            ts=0;
            while((n%primes[i])==0)
            {
                ts++;
                n/=primes[i];
            }
            ndiv*=(ts+1);
        }
        if(n>1) ndiv*=2;
        if((lim*lim)==nc) modulo(lim,ndiv-2);
        else modulo(nc,((ndiv-2)/2));
        /*if(flag==false) printf("%d\n",ans);
        else
        {
            if(ans<10) printf("000");
            else if(ans<100) printf("00");
            else if(ans<1000) printf("0");
            printf("%d\n",ans);
        }*/
    }
    return 0;
}
Ejemplo n.º 25
0
void overmapbuffer::spawn_monster(const int x, const int y, const int z)
{
    // Create a copy, so we can reuse x and y later
    point sm( x, y );
    const point omp = sm_to_om_remain( sm );
    overmap &om = get( omp.x, omp.y );
    for( auto it = om.monsters.begin(); it != om.monsters.end(); ) {
        auto &mdata = *it;
        if( sm.x == mdata.x && sm.y == mdata.y && z == mdata.z ) {
            monster &critter = mdata.mon;
            // The absolute position in map squares, (x,y) is already global, but it's a
            // submap coordinate, so translate it and add the exact monster position on
            // the submap. modulo because the zombies position might be negative, as it
            // is stored *after* it has gone out of bounds during shifting. When reloading
            // we only need the part that tells where on the sumap to put it.
            point ms( modulo( critter.posx(), SEEX ), modulo( critter.posy(), SEEY ) );
            if( ms.x < 0 ) {
                ms.x += SEEX;
            }
            if( ms.y < 0 ) {
                ms.y += SEEY;
            }
            assert( ms.x >= 0 && ms.x < SEEX );
            assert( ms.y >= 0 && ms.y < SEEX );
            ms.x += x * SEEX;
            ms.y += y * SEEY;
            // The monster position must be local to the main map when added via game::add_zombie
            const point local = g->m.getlocal( ms.x, ms.y );
            assert( g->m.inbounds( local.x, local.y ) );
            critter.spawn( local.x, local.y );
            g->add_zombie( critter );
            it = om.monsters.erase( it );
        } else {
            ++it;
        }
    }
}
Ejemplo n.º 26
0
Archivo: eval.c Proyecto: BigEd/pyldin
void emit(int tt, unsigned int tval)
{
  if(tt == UNKNOWN)
    error("Unknown token");
  else if(tt == DONE)
    error("Unexpected end of expression");
  else if(tt == NONE)
    error("No token in expression");
  else if(tt == EOS)
    error("End of string in expression");
  else if(tt == NUM)
    push(tt, tval);
  else if(tt == STRING) {
    if(tval <= 0)
      error("Unrecognized expression");
    else
      push(tt, tval);
  }
  else {
    /* apply operator */
    switch(tt) {
      case 1:  l_orr();      break;
      case 2:  l_and();      break;
      case 3:  b_orr();      break;
      case 4:  b_xor();      break;
      case 5:  b_and();      break;
      case 6:  l_equ();      break;
      case 7:  l_neq();      break;
      case 8:  l_leq();      break;
      case 9:  l_geq();      break;
      case 10: l_ltt();      break;
      case 11: l_gtt();      break;
      case 12: lshift();     break;
      case 13: l_rshift();   break;
      case 14: rshift();     break;
      case 15: plus();       break;
      case 16: minus();      break;
      case 17: multiply();   break;
      case 18: divide();     break;
      case 19: modulo();     break;
      case 20: l_not();      break;
      case 21: b_not();      break;
      case 22: unaryminus(); break;
      case 23: unaryplus();  break;
      default:
        error("Unknown operator");
    }
  }
}
Ejemplo n.º 27
0
/**
 * If timezone present - xmlnormalize dateTime  [E Adding durations to dateTimes]
 *
 * @param date   CCYY-MM-DDThh:mm:ss+03
 * @return CCYY-MM-DDThh:mm:ssZ
 */
void TimeVal::xmlnormalize()
{

  if ((parser_context.fValue[utc] == UTC_UNKNOWN) ||
      (parser_context.fValue[utc] == UTC_STD)      )
    return;

  int negate = (parser_context.fValue[utc] == UTC_POS)? -1: 1;

  // add mins
  int temp = parser_context.fValue[Minute] + negate * parser_context.fTimeZone[mm];
  int carry = fQuotient(temp, 60);
  parser_context.fValue[Minute] = mod(temp, 60, carry);

  //add hours
  temp = parser_context.fValue[Hour] + negate * parser_context.fTimeZone[hh] + carry;
  carry = fQuotient(temp, 24);
  parser_context.fValue[Hour] = mod(temp, 24, carry);

  parser_context.fValue[Day] += carry;

  while (1)
    {
      temp = maxDayInMonthFor(parser_context.fValue[CentYear], parser_context.fValue[Month]);
      if (parser_context.fValue[Day] < 1)
        {
	  parser_context.fValue[Day] += maxDayInMonthFor(parser_context.fValue[CentYear], parser_context.fValue[Month] - 1);
	  carry = -1;
        }
      else if ( parser_context.fValue[Day] > temp )
        {
	  parser_context.fValue[Day] -= temp;
	  carry = 1;
        }
      else
        {
	  break;
        }

      temp = parser_context.fValue[Month] + carry;
      parser_context.fValue[Month] = modulo(temp, 1, 13);
      parser_context.fValue[CentYear] += fQuotient(temp, 1, 13);
    }

  // set to xmlnormalized
  parser_context.fValue[utc] = UTC_STD;

  return;
}
Ejemplo n.º 28
0
void bitarray_rotate(bitarray_t *const bitarray,
                     const size_t bit_offset,
                     const size_t bit_length,
                     const ssize_t bit_right_amount) {
  assert(bit_offset + bit_length <= bitarray->bit_sz);

  if (bit_length == 0) {
    return;
  }

  // Convert a rotate left or right to a left rotate only, and eliminate
  // multiple full rotations.
  bitarray_rotate_left(bitarray, bit_offset, bit_length,
           modulo(-bit_right_amount, bit_length));
}
Ejemplo n.º 29
0
void			ft_cmd(t_env *e, int fd)
{
	char	cmd[BUF_SIZE + 1];
	int		i;

	bzero(cmd, BUF_SIZE + 1);
	while (e->clients[fd].cbuf[modulo((e->clients[fd].end - 1)
		, BUF_SIZE)] == '\n'
		&& e->clients[fd].end != e->clients[fd].start)
	{
		i = 0;
		while (e->clients[fd].cbuf[modulo((e->clients[fd].end - 1)
			, BUF_SIZE)] == '\n'
			&& e->clients[fd].cbuf[modulo(e->clients[fd].start
				, BUF_SIZE)] != '\n')
		{
			cmd[i++] = e->clients[fd].cbuf[e->clients[fd].start];
			e->clients[fd].start = (e->clients[fd].start + 1) % BUF_SIZE;
		}
		ft_cmd2(e, cmd, fd);
		ft_strclr(cmd);
		e->clients[fd].start = (e->clients[fd].start + 1) % BUF_SIZE;
	}
}
Ejemplo n.º 30
0
int moduloTest() {
  cl_int error = CL_SUCCESS;

  fprintf (stdout, "========= MODULO PRECISION TEST =========\n");
  error = init_modulo();
  cl_int num = -30;
  cl_float amount = 0.123145;
  cl_float mod = 0;
  error += modulo(&num, &mod, &amount);
  fprintf (stdout, "CL exceution = %f\n", mod);
  cl_float res = (num - 50) / (amount * 2.0);
  res = (res * res) * res;
  fprintf (stdout, "C  execution = %f\n", res);
  return error;
}