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:

    Most literature on the culture of adolescence focuses on peer pressure as a negative force. Warnings about the “wrong crowd” read like tornado alerts in parent manuals. . . . It is a relative term that means different things in different places. In Fort Wayne, for example, the wrong crowd meant hanging out with liberal Democrats. In Connecticut, it meant kids who weren’t planning to get a Ph.D. from Yale.
    Mary Kay Blakely (20th century)

    Our role is to support anything positive in black life and destroy anything negative that touches it. You have no other reason for being. I don’t understand art for art’s sake. Art is the guts of the people.
    Elma Lewis (b. 1921)