Using #define

ggarciabas (1)
Hello,
I created a simple file to calculate a bisection and I had problems with the #define.

I used this structure:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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 (long double a, long double b, long double e, int n, int i) 
{
	long double __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.

Thank you,
GGarciaBas
kbw (5371)
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.
Registered users can post here. Sign in or register to post.