isn't there an operator in c to change the sign of a int float etc from negative to positive or vice versa?

nickthedude picture nickthedude · Jan 8, 2010 · Viewed 24.5k times · Source

trying to find absolute value and i thought there was a simple way to just invert the sign with '~' or something.

Answer

Beep beep picture Beep beep · Jan 8, 2010
float newValue = oldValue * -1;

or

float newValue = -(oldValue); //() aren't needed, I just use them out of habit