#define __e 0.01 // define o erro
#define f1x (pow(__x,2) - 5) // define F(x)
#define f1a (pow(a,2) - 5) // define F(a)
#define f1b (pow(b,2) - 5) // define F(b)
...
int main ()
{
...
bisseccao (__a, __b, __e, 0, i);
return 0;
}
void bisseccao (longdouble a, longdouble b, longdouble e, int n, int i)
{
longdouble __x = (a + b) / 2, fa, fb;
if (++n <= i && erro >= e) {
fa = f1a;
fb = f1b;
...
}
....
}
And in the function bisseccao () I have fa, a simple variable and I want that variable receive the result of the f1a ( defined on #define), but the result is wrong.
This is correct? If not, could some one help me, I need to do something like this, I need to inform the equation and calculate them.
That isn't quite right in principle. But rather than wasting time fixing that, as you're using C++, why not use functions? You can inline them if you feel you need them to be inline.
But kbw is right, it's better to use functions than macros. Macros can cause some strange things.
Example:
using this macro: #define max(a,b) (((a) < (b))?(b):(a))
like this: max(i++, 0);
will give you this: (((i++) < (0))?(0):(i++));
i get's incremented twice!
Thank you guys.
Can I get to the user's equation on running the program and use then to calculate a value of any number, I said, define the equation to the variable in the program execution?