Is there any syntax that will return the opposite value of plus and negative.
It should be one syntax that take the opposite. It must work both directions.
So for these examples:
Code:
5 //This will return -5
-4 //This will return 4
Printable View
Is there any syntax that will return the opposite value of plus and negative.
It should be one syntax that take the opposite. It must work both directions.
So for these examples:
Code:
5 //This will return -5
-4 //This will return 4
Well, if you have a number x, -x is such an opposite.
That did work actually. So if you just write like in you example a - before x like -x.
This will make + to - and - to +. I thought that only would work from + to -.
Then if x is - from the beginning it must be a kind of multiplication -(-x) makes plus I beleive.
Thanks
Not multiplication, but just subtraction.Quote:
Then if x is - from the beginning it must be a kind of multiplication -(-x) makes plus I beleive.
-(-x) = 0 - (-x) = 0 - (0 - x)
Then I think I understand. Thanks.