コード例 #1
0
ファイル: TestPointsOnAPlane.cpp プロジェクト: Yonghuizz/ogs
TEST(GeoLib, TestPointsOnAPlane)
{
	// 2d case
	GeoLib::Point a(0,0,0);
	GeoLib::Point b(1,0,0);
	GeoLib::Point c(0,1,0);
	GeoLib::Point d(1,1,0);
	testAllPossibilities(a, b, c, d, true);

	// disturbe z coordinate of point d
	d[2] = 1e6*std::numeric_limits<double>::epsilon();
	testAllPossibilities(a, b, c, d, true);

	// disturbe z coordinate of point d
	d[2] = 1e-9;
	testAllPossibilities(a, b, c, d, true);
	d[2] = 1e-6;
	testAllPossibilities(a, b, c, d, true);
	d[2] = 1e-5;
	testAllPossibilities(a, b, c, d, false);

	// irregular case: a = d = ORIGIN
	d = GeoLib::Point(0.0, 0.0, 0.0);
	testAllPossibilities(a, b, c, d, true);

	// irregular case: a = b = d = ORIGIN
	b = GeoLib::Point(0.0, 0.0, 0.0);
	testAllPossibilities(a, b, c, d, true);

	// irregular case: a = b = c = d
	c = GeoLib::Point(0.0, 0.0, 0.0);
	testAllPossibilities(a, b, c, d, true);

	// 2d case with fixed z
	a = GeoLib::Point(0.0, 0.0, 0.3);
	b = GeoLib::Point(1e-5, 0.0, 0.3);
	c = GeoLib::Point(0.0, 1e-5, 0.3);
	d = GeoLib::Point(1e-5, 1e-5, 0.3);
	testAllPossibilities(a, b, c, d, true);

	// a,b,c with random coordinates,
	std::uniform_real_distribution<double> distri(-1e10, 1e10);
	std::default_random_engine re;
	for (std::size_t k(0); k<1000; k++) {
		a = GeoLib::Point(distri(re), distri(re), distri(re));
		b = GeoLib::Point(distri(re), distri(re), distri(re));
		c = GeoLib::Point(distri(re), distri(re), distri(re));
		// d such that it is in the plane
		d = GeoLib::Point(b[0]+c[0]-a[0], b[1]+c[1]-a[1], b[2]+c[2]-a[2]);
		testAllPossibilities(a, b, c, d, true);
		// d such that it is not in the plane
		d[2] = std::numeric_limits<double>::epsilon() +
			(1 + std::numeric_limits<double>::epsilon())*(b[2]+c[2]);
		testAllPossibilities(a, b, c, d, false);
	}
}
コード例 #2
0
ファイル: WideVM.cpp プロジェクト: FRex/WideVM
void WideVM::opRand2()
{
    const int to = fetch();
    const int min = fetch();
    const int max = fetch();

    while(loopParticles())
    {
        std::uniform_real_distribution<float> distri(read(min), read(max));
        write(to) = distri(m_twister);
    }
}
コード例 #3
0
ファイル: GivensRotation.cpp プロジェクト: risi-kondor/pMMF
GivensRotation::GivensRotation(const Random dummy, const int n) {
	uniform_int_distribution<int> distri(0, n - 1);
	uniform_real_distribution<FIELD> distrr(0, 1);
	i1 = distri(randomNumberGenerator);
	i2 = i1;
	while (i2 == i1) {
		i2 = distri(randomNumberGenerator);
	}
	if (i2 > i1)
		swapp(i1, i2);
	cos = distrr(randomNumberGenerator);
	sin = sqrt(1 - cos * cos);
}
コード例 #4
0
GameID BattleshipApp::GetValidID()
{
    GameID id = 0U;

    do
        id = distri(rand_eng);
    while (game_map.find(id) != game_map.end());

    return id;
}
コード例 #5
0
 int maximalSquare(vector<vector<char>>& matrix) {
     int rows = matrix.size();
     int cols = rows?matrix[0].size():0;
     
     int maxsize = 0;
     vector<vector<int>> distri(rows, vector<int>(cols, 0));
     for(int i = 0; i < rows; i++) {
         for(int j = 0; j < cols; j++) {
             // 边界条件
             if(i == 0 || j == 0) {
                 distri[i][j] = matrix[i][j]-'0';
                 maxsize = max(maxsize, distri[i][j]);
                 continue;
             }
             // 非边界部分
             if(matrix[i][j] == '1') {
                 distri[i][j] = min(distri[i-1][j-1], min(distri[i-1][j], distri[i][j-1])) + 1;
                 maxsize = max(maxsize, distri[i][j]);
             }
         }
     }
     return maxsize*maxsize;
 }
コード例 #6
0
ファイル: test.c プロジェクト: cpu2015g6/FPU
int main(int argc, char*argv[]){
  int failed=0;
  uint32_t i;
  uint32_t result;
  uint32_t out;
  int aaa[1024];
  int k=0;
  int m=0;
  int del = 0;
  int table[128];

  if(argc < 4){
   printf("few args!!\n");
   return 1;
  }

  i=0;
  while(i<128){
    table[i]=0;
    i++;
  }
  int offset = atoi(argv[1]);
  int offset_term = atoi(argv[2]);
  i=(127<<23) + (offset << 13);

  int j=0 - (atoi(argv[3]));
  int dist=1000;
  int best=0;

  while(offset < offset_term){

    dist=1000;
    j=0 - (atoi(argv[3]));

    while(j < atoi(argv[3]) + 1){

      k=0;
      i=(127<<23) + (offset << 13);

      while(k < 8192*1024){
	result=finv_s(i);
	out = finv(i,j);
	del = out - result;
	/*if(del > 4 || del < -4){
	  printf("offset: %d\n",offset);
	  printf("del: %d\n",del);
	  printbin(i);
	  printbin(out);
	  printbin(result);
	  return 0;
	  }*/
	table[del+64] = table[del+64]+1;
	k++;
	i++;
      }
      
      printtable(table);
      return 1;
      

      if(distri(table) < dist){
	best = j;
	dist = distri(table);
      }

      m=0;
      while(m<128){
	table[m]=0;
	m++;
      }
      
      j++;
    }
    
    k=0;
    i=(127<<23) + (offset << 13);
     while(k < 8192){
	result=finv_s(i);
	out = finv(i,best);
	del = out - result;
	table[del+64] = table[del+64]+1;
	k++;
	i++;
      }

     //print23bin(ctou(dummy[offset]));
     //printtable(table);
     //printf("%d\n",lub(table));
     aaa[offset] = 0 - ((lub(table)+glb(table)) /2);
     /*m=0;
     while(m<128){
       table[m]=0;
       m++;
     }*/
    
     if(dist < 10){
       fprintf(stderr,"clear: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table));
    }else{
       fprintf(stderr,"FAILED...: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table));
      failed++;
      }
    fprintf(stderr,"sinchoku...%d/%d\n",offset-atoi(argv[1]),atoi(argv[2])-atoi(argv[1]));
    incdecprint2(dummy2,best,offset);

      m=0;
      while(m<128){
	table[m]=0;
	m++;
      }

      offset++;
  }
  offset=atoi(argv[1]);
  while(offset < atoi(argv[2])){
    incdecprint(dummy,aaa[offset],offset);
    offset++;
  }

	//printf("best case: %d dist: %d\n",best,dist);
  fprintf(stderr,"failed cases: %d/%d\n",failed,atoi(argv[2])-atoi(argv[1]));
  
  return 0;
}