Explanation of a code line sought

Hi there. In this web page

http://www.holoborodko.com/pavel/?page_id=679

there is a reference (link) to a zip file (Gauss-Legendre Quadrature.zip) and if you unzip it you will find some code with a couple of routines. One of them is this:

 
 double gauss_legendre_2D_cube(int n, double (*f)(double,double,void*), void* data, double a, double b, double c, double d)


I want to understand how to interpret it. What does double (*f)(double,double,void*) mean? It is a sort of a pointer but to what?

Thanks, - Alex
Last edited on
A pointer to a function.
The idea is that you should be able to compute the integral of any 2d function, so you ask it as a parameter.
Those function receive a pair x,y of coordinates, and a pointer to any data that they may need.


By instance
1
2
3
4
5
6
7
8
9
10
double sine_2d(double x, double y, void *){
   return sin(x*y);
}
double cosine_2d(double x, double y, void *){
   return cos(x*y);
}

//then you can compute the integral
gauss_legendre_2D_cube(5, sine_2d, nullptr, /**/);
gauss_legendre_2D_cube(5, cosine_2d, nullptr, /**/);
ne555, thank you. I actually did not notice that this routine is 2D. The package has a one-D variant with a one-dimensional integrand and this is the routine I actually need.

double gauss_legendre(int n, double (*f)(double,void*), void* data, double a, double b)

Thanks, - Alex
Topic archived. No new replies allowed.