Reputation: 7766
I'm thinking there must be a function to do both. I think fabs will do negative to positive.
But not sure about the other way around ?
Upvotes: 7
Views: 10277
Reputation: 505
I would rather write like this:
num = -num;
This won't need a multiplication, just changing the sign.
Upvotes: 13
Reputation: 726629
num *= -1
will change the sign from positive to negative and vice versa.
Upvotes: 16