I dont understand why a simple function 'fabs' is not working when I use a double argument d_bend!!! It works only when I typecast it with 'long' as done below.
VC++ 6.0 is s**t. It's already over ten years old and its standard compliance is illusory. It's not surprising that it doesn't have a function like fabs().
I recommend changing your compiler, but if that's not an option (for whatever reason) try using abs() instead, which has the same overloads as abs() (which makes me wonder why they even bothered to include fabs() in the standard).
So strange!! It does not work even with 'abs'.
In the beginning it worked when I used 'abs' along with 'long' type-casting. But now its not working, I dont understand it all.
Can somebody please help me? Btw, all the variables in the code-snippet I put above are of type 'double'.
There can be many workarounds, but I want to know the 'real' reason ;). You see, its got to do with some basic concept of typecasting, which I want to learn. Moreover I write this function and later I would like to invoke this function from Python, which in itself is a big headache. I managed to find a solution for calling a function from C using SWIG, so now I dont want to break my head further on trying to find out what do with 'define macros' if it should also be visible in Python.
The function is a black box when called from Python. All you'll see are the parameters you pass, and the results it returns. Python will only see the compiled file (either a lib or an .o, I can't remember) and the definition (in Python) you provide. How you perform the operations will remain invisible inside the black box.
There must be something wrong with your installation. I just wrote and compiled with without problems:
1 2 3 4 5 6 7 8
#include <iostream.h>
#include <math.h>
int main(){
long a=-14;
cout <<fabs(a)<<endl;
return 0;
}
I am really sorry. Have found my mistake, it was more down to the formula than due to fabs/abs.
The only reason why I doubted fabs was because the output seems correct on few occassions which actually was not the case, but actually a wrong interpretation of values from my side.
Thank you everybody, especially Helios for sparing the time.