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?
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?
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.