473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Arbitrary function with parameter

Hi, I would like to know how to define a arbitrary mathematical
function with one variable and a list of paramter, like, f(x). For
example, in GSL library this is done as
/* Definition of an arbitrary function with parameters */

struct gsl_function_struct
{
double (* function) (double x, void * params);
void * params;
};

typedef struct gsl_function_struct gsl_function ;

#define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params)

and the usage is here:
http://www.gnu.org/software/gsl/manu...ction-to-solve

I wonder how one does it in C++?

Thanks.

Jul 21 '06 #1
2 2441
da*******@gmail.com wrote:
Hi, I would like to know how to define a arbitrary mathematical
double (* function) (double x, void * params);
http://www.gnu.org/software/gsl/manu...ction-to-solve
I wonder how one does it in C++?
If you're using gnu stuff anyway, "man stdarg" should do the trick (has
an example).
googling should tell you how to use it on different systems too.

Jul 21 '06 #2
da*******@gmail.com wrote:
Hi, I would like to know how to define a arbitrary mathematical
function with one variable and a list of paramter, like, f(x). For
example, in GSL library this is done as
/* Definition of an arbitrary function with parameters */

struct gsl_function_struct
{
double (* function) (double x, void * params);
void * params;
};

typedef struct gsl_function_struct gsl_function ;

#define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params)

and the usage is here:
http://www.gnu.org/software/gsl/manu...ction-to-solve

I wonder how one does it in C++?
In C++, one would use a functor. See this for a description:

http://www.sgi.com/tech/stl/functors.html

See especially the example involving struct less_mag.

Cheers! --M

Jul 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
9
by: Andrew | last post by:
It seems that in C#, given an instance "a" of some value type "A", one can pass a by reference to functions with signatures of either "void f(object obj)" or "void g(ref A obj)". But passing a into...
5
by: Honestmath | last post by:
Hello everyone, I'm using a root finding algorithm in a function that only takes as arguments a function pointer and two variables that represent guesses at the roots of the function. int...
8
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { }...
12
by: Chadwick Boggs | last post by:
I need to perform modulo operations on extremely large numbers. The % operator is giving me number out of range errors and the mod(x, y) function simply seems to return the wrong results. Also,...
5
by: Steven D'Aprano | last post by:
I have a problem and I don't know where to start looking for a solution. I have a class that needs to call an arbitrary function and wait for a result. The function, being completely arbitrary...
3
by: Curtis | last post by:
Hello everyone: Recently, I've come across the need to accept an arbitrary amount of arguments in my function, but I also need to alter the data in the calling scope. I have been trying to...
2
by: John O'Hagan | last post by:
Hi Pythonistas, I'm looking for the best way to pass an arbitrary number and type of variables created by one function to another. They can't be global because they may have different values...
0
by: John O'Hagan | last post by:
On Tue Sep 30 11:32:41 CEST 2008, Steven D'Aprano Thanks, both to you and Bruno for pointing this out, I'll certainly be using it in future.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.