URL
https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk
Subversion Repositories openrisc_me
[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [g++.old-deja/] [g++.robertl/] [eb120.C] - Rev 414
Go to most recent revision | Compare with Previous | Blame | View Log
// { dg-do run }
template<double functionToIntegrate(double)>
double integrate(double a, double b, int numSamplePoints)
{
// PRECONDITION(numSamplePoints > 1);
double delta = (b-a) / (numSamplePoints-1);
double sum = 0.;
for (int i=0; i < numSamplePoints; ++i)
sum += functionToIntegrate(a + i*delta);
return sum * (b-a) / numSamplePoints;
}
inline double myFunction(double x)
{
return 1 / (1 + x);
}
// Example use
int main() {
double z = integrate<myFunction>(0.0, 1.0, 50);
return 0 ;
}
Go to most recent revision | Compare with Previous | Blame | View Log