Problem with Absolute Value Comparison

Jul 12, 2011 at 2:47am
I'm having trouble with the abs function. I have two variables - my_abs_minimum and r, both are type double. I need to compare my_abs_minimum to the absolute value of r. Here is what I am doing:

1
2
if ((my_abs_minimum > double abs (r)) || (my_length == 1)) 
            my_abs_minimum = double abs (r);


I'm getting two errors:
'expected primary expression before "double"'
and
"expected ')' before ';' token"

I've played with this every way that I can think of, but I can't get it to compile. Can anyone help? Thanks.
Jul 12, 2011 at 2:50am
Remove the word double in both instances?
Jul 12, 2011 at 2:53am
That's how this whole thing started. Without the word double, I get this warning:

"passing 'double' for converting 1 of 'int abs(int)'"

I researched the abs function and found that I needed the double to prevent it from converting back to an integer. At least, that was my conclusion, for better or worse.
Last edited on Jul 12, 2011 at 2:54am
Jul 12, 2011 at 2:56am
Oh you're using the cmath abs? or the math.h abs?

Also what compiler and IDE are you using?
Jul 12, 2011 at 2:58am
cmath. IDE is wxDev-C++
Jul 12, 2011 at 3:02am
Can you show us more of your code?
Jul 12, 2011 at 3:13am
Not really feasible. This is part of a fairly long class implementation and I don't know how to strip the code to something that would make the issue any simpler.

I figured out a way to solve it. Rather than mess around with casting the abs function as double, I changed my abs function call from abs to fabs. I found something that says that that is what you do when your argument is double rather than int.

It works now. Thanks for your help!
Topic archived. No new replies allowed.