Unary Operation - Unary Negative and Positive

Unary Negative and Positive

As unary operations have only one operand they are evaluated before other operations containing them. Here is an example using negation:

3 − −2

Here the first '−' represents the binary subtraction operation, while the second '−' represents the unary negation of the 2. Therefore, the expression is equal to:

3 − (−2) = 5

Technically there is also a unary positive but it is not needed since we assume a value to be positive:

(+2) = 2

Unary positive does not change the sign of a negative operation:

(+(−2)) = (−2)

In this case a unary negative is needed to change the sign:

(−(−2)) = (+2)

Unary operators (called "monadic" in APL) are also used in programming languages.

Read more about this topic:  Unary Operation

Famous quotes containing the words negative and/or positive:

    The working woman may be quick to see any problems with children as her fault because she isn’t as available to them. However, the fact that she is employed is rarely central to the conflict. And overall, studies show, being employed doesn’t have negative effects on children; carefully done research consistently makes this clear.
    Grace Baruch (20th century)

    As for the terms good and bad, they indicate no positive quality in things regarded in themselves, but are merely modes of thinking, or notions which we form from the comparison of things with one another. Thus one and the same thing can be at the same time good, bad, and indifferent. For instance music is good for him that is melancholy, bad for him who mourns; for him who is deaf, it is neither good nor bad.
    Baruch (Benedict)