objective-coperatorsabsolute-valuenegate

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


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


Solution

  • float newValue = oldValue * -1;
    

    or

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