示例#1
0
int fun4(int i, int j) {
  if (i > j) {
    return fun0(i - 1, j + 1);
  } else {
    return j - i;
  }
}
void test1 () {
    struct V {
        float x = 1.0f;
        float GetX() const { return x; } 
        V() {}
    } const v;
    Class c;
    const Class cc;
    Fun< int (int) >   fun0;
    Fun< int (int) >   fun1(&Twice);  
    Fun< int (int) >   fun2(&Class::Twice);
    Fun< int () >      fun3(&VoidParam);
    Fun< int () >      fun4(&Class::VoidParam);
    Fun< int () >      fun5(&Class::VoidParamConst);
    Fun< void(int&) >  fun6(&Class::Void);
    Fun< int (int) >   fun7((Functor()));
    auto               fun8(RetFun());
    Fun< float (int, int) > fun9([=](int i, int j) {return float(i/j);});
    Fun< float (int, int) > fun10(fun9);
    Fun< float () > fun11([v](){return v.GetX();});
    Fun< void() > vd;

    try { 
         fun0(9); //must throw
         assert(false);
    } catch(...) {}
    fun0 = fun1;
    assert(fun0(2)    == fun1(2));
    assert(fun1(2)    ==  4);
    assert(fun2(c, 3) ==  6);
    assert(fun5(cc)   ==  2);
    assert(fun7(6)    == 18);
    assert(fun8(7)    == 21);
    assert(fun9(10,4) == float(10/4));
    assert(fun10(20, 8) == fun9(20, 8));
    assert(fun11() == 1.0f);
    //void return type
    int i = 0;
    fun6(c, i);
    assert(i == 1234);
}
示例#3
0
文件: 8878523_PE.cpp 项目: chyyuu/ACM
int main()
{
	//freopen("1489in.txt","r",stdin);
	//freopen("1489out.txt","w",stdout);
int i,j,k;
int n,p;
fun0();

char str1[100],str2[100];

while(1)
{

    str1[0]=getchar();
    if(str1[0]==10)break;
    for(i=1;;i++)
    {
    str1[i]=getchar();
    if(str1[i]==10){str1[i]='\0';break;}             
    }
    for(i=0;;i++)
    {
    str2[i]=getchar();
    if(str2[i]==10){str2[i]='\0';break;}             
    }
int x1=fun2(str1);//printf("%d %s\n",x1,str1);
int x2=fun2(str2);//printf("%d %s\n",x2,str2);
int x3=x1*x2;

n=x2;
for(i=0;;i++)
{
    p=n%2;
    if(p)cstr0[i][istr1[i]]='*';
    printf("%s%s\n",cstr0[i],fun3(x1));	
    if(p)cstr0[i][istr1[i]]=' ';
    x1*=2;
    n/=2;
    if(n==0)break;	
}	
printf("The solution is: %s\n",fun3(x3));
	
}

	//getchar();getchar();
return 0;	
}
int main(int argc, const char * argv[]) {

  int i;

  i =1;

  while ( i > 0) {

    i=fun0(i);

  }


  float f = i;
   
  if(i<0) printf(" precision is %f bits \n",log(-f)/log(2.)+1);
  
  return 0;
}
示例#5
0
/// Execute algorithm.
void Schrodinger1D::exec()
{
  double startX = get("StartX");
  double endX = get("EndX");

  if (endX <= startX)
  {
    throw std::invalid_argument("StartX must be <= EndX");
  }

  IFunction_sptr VPot = getClass("VPot");
  chebfun vpot( 0, startX, endX );
  vpot.bestFit( *VPot );

  size_t nBasis = vpot.n() + 1;
  std::cerr << "n=" << nBasis << std::endl;
  //if (n < 3)
  {
    nBasis = 200;
    vpot.resize( nBasis );
  }

  const double beta = get("Beta");

  auto kinet = new ChebCompositeOperator;
  kinet->addRight( new ChebTimes(-beta) );
  kinet->addRight( new ChebDiff2 );
  auto hamiltonian = new ChebPlus;
  hamiltonian->add('+', kinet );
  hamiltonian->add('+', new ChebTimes(VPot) );

  GSLMatrix L;
  hamiltonian->createMatrix( vpot.getBase(), L );

  GSLVector d;
  GSLMatrix v;
  L.diag( d, v );

  std::vector<double> norms = vpot.baseNorm();
  assert(norms.size() == L.size1());
  assert(norms.size() == L.size2());

  for(size_t i = 0; i < norms.size(); ++i)
  {
      double factor = 1.0 / norms[i];
      for(size_t j = i; j < norms.size(); ++j)
      {
          v.multiplyBy(i,j,factor);
      }
  }

//  eigenvectors orthogonality check
//  GSLMatrix v1 = v;
//  GSLMatrix tst;
//  tst = Tr(v1) * v;
//  std::cerr << tst << std::endl;

  std::vector<size_t> indx(L.size1());
  getSortedIndex( d, indx );

  auto eigenvalues = API::TableWorkspace_ptr(dynamic_cast<API::TableWorkspace*>(
    API::WorkspaceFactory::instance().create("TableWorkspace"))
    );
  eigenvalues->setRowCount(nBasis);
  setProperty("Eigenvalues", eigenvalues);

  eigenvalues->addColumn("double","N");
  auto nColumn = static_cast<API::TableColumn<double>*>(eigenvalues->getColumn("N").get());
  nColumn->asNumeric()->setPlotRole(API::NumericColumn::X);
  auto& nc = nColumn->data();

  eigenvalues->addDoubleColumn("Energy");
  auto eColumn = static_cast<API::TableColumn<double>*>(eigenvalues->getColumn("Energy").get());
  eColumn->asNumeric()->setPlotRole(API::NumericColumn::Y);
  auto& ec = eigenvalues->getDoubleData("Energy");

  boost::scoped_ptr<ChebfunVector> eigenvectors(new ChebfunVector);

  chebfun fun0(nBasis,startX,endX);
  ChebFunction_sptr theSum(new ChebFunction(fun0));

  // collect indices of spurious eigenvalues to move them to the back
  std::vector<size_t> spurious;
  // index for good eigenvalues
  size_t n = 0;
  for(size_t j = 0; j < nBasis; ++j)
  {
    size_t i = indx[j];
    chebfun fun(fun0);
    fun.setP(v,i);

    // check eigenvalues for spurious ones
    chebfun dfun(fun);
    dfun.square();
    double norm = dfun.integr();

    // I am not sure that it's a solid condition
    if ( norm < 0.999999 )
    {
        // bad eigenvalue
        spurious.push_back(j);
    }
    else
    {
        nc[n] = double(n);
        ec[n] = d[i];
        eigenvectors->add(ChebFunction_sptr(new ChebFunction(fun)));

        // test sum of functions squares
        *theSum += dfun;

//        chebfun dfun(fun);
//        hamiltonian->apply(fun,dfun);
//        dfun *= fun;
//        std::cerr << "ener["<<n<<"]=" << ec[n] << ' ' << norm << ' ' << dfun.integr() << std::endl;
        ++n;
    }
  }

  GSLVector eigv;
  ChebfunVector *eigf = NULL;
  improve(hamiltonian, eigenvectors.get(), eigv, &eigf);

  eigenvalues->setRowCount( eigv.size() );
  for(size_t i = 0; i < eigv.size(); ++i)
  {
      nc[i] = double(i);
      ec[i] = eigv[i];
  }

  eigf->add(theSum);
  setProperty("Eigenvectors",ChebfunVector_sptr(eigf));

  //makeQuadrature(eigf);

}
示例#6
0
int main(int argc, char** argv) {
  int i0 = argv[0][0];
  int i1 = argv[0][1];
  printf("%d\n", fun0(i0, i1));
}