Converting a postive integer to a negative

Viewed 85

I am new to programming and was curious to know why the following returns a negative integer:

-num.abs

My understanding is that abs returns the value as a positive number yet this will return any positive number into a negative?

1 Answers

why the following returns a negative integer: -num.abs

Because it's -(num.abs), not (-num).abs. First, you take abs, then you negate that value, resulting in a negative number.

Related