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:

    Coming out, all the way out, is offered more and more as the political solution to our oppression. The argument goes that, if people could see just how many of us there are, some in very important places, the negative stereotype would vanish overnight. ...It is far more realistic to suppose that, if the tenth of the population that is gay became visible tomorrow, the panic of the majority of people would inspire repressive legislation of a sort that would shock even the pessimists among us.
    Jane Rule (b. 1931)

    Blessed be the inventor of photography! I set him above even the inventor of chloroform! It has given more positive pleasure to poor suffering humanity than anything else that has “cast up” in my time or is like to—this art by which even the “poor” can possess themselves of tolerable likenesses of their absent dear ones. And mustn’t it be acting favourably on the morality of the country?
    Jane Welsh Carlyle (1801–1866)