Added to Favorites

Popular Searches

Definitions

In mathematics, a unary operation is an operation with only one operand, i.e. an operation with a single input, or in other words, a function of one variable (for the terminology see also operators versus functions). ## Unary Negative and Positive

## Examples of Unary operations

## Computer programming

Unary operators (called "monadic" in APL) are also used in programming languages.
### C family of languages

In the C family of languages, the following operators are unary:### Other languages

#### Windows PowerShell

### Usage of Incremental and Decremental operators

In most programming languages, incremental and decremental operators can be prefixed and suffixed to the variable. The prefix and suffix can be useful when manipulating variables. A suffixed operation increments the value after it has been called.#### Example 1

Common notations are prefix notation (+, −, not), postfix notation (factorial: n!), and functional notation (sin x or sin (x)). In the case of the square root a horizontal bar over the argument extending the square root sign can indicate the extent of the argument, so that parentheses can be dispensed with.

As unary operations have only one oprand they are evaluated before other operations containing them are. In this example using addition:

3 − −2

Here the first '−' represents the binary subtraction operation, while the second '−' represents the unary negation of the two, a clearer way to write the expression would be:

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 the case a unary negative is needed to change the sign:

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

- the absolute value operation is a unary operation on the real numbers
- the opposite operation (−x) on the real numbers
- the power operations (squaring, cubing, etc) on the real numbers
- the factorial operation on the non-negative integer numbers
- the trigonometric functions (sin x, cos x, tan x, cot x, csc x, sec x) on the real numbers
- the natural logarithm (ln x) on the real numbers
- the logarithm of base 10 (log x) on the real numbers
- logical negation on truth values
- A unary operation on a given set S is a function S → S, also called an endomorphism of S.

- Increment:
`++x, x++`

- Decrement:
`−−x, x−−`

- Address:
`&x`

- Indirection:
`*x`

- Positive:
`+x`

- Negative:
`−x`

- One's complement:
`~x`

- Logical negation:
`!x`

- Sizeof:
`sizeof x, sizeof(type-name)`

- Cast:
`(type-name) cast-expression`

- Increment:
`++$x, $x++`

- Decrement:
`−−$x, $x−−`

- Positive:
`+$x`

- Negative:
`−$x`

- Logical negation:
`-not $x`

- Invoke in current scope:
`.$x`

- Invoke in new scope:
`&$x`

- Cast:
`[type-name] cast-expression`

Order of evaluation for arguments in function calls is unspecified according to C99. Because of this, a compiler might produce results that appear to be transposed. The output of the examples below are compiler-specific and depends on implementation. To avoid this behavior and minimize dependence, the code could be rewritten.

In the examples below, the integer arguments are evaluated left to right.

Wikipedia, the free encyclopedia © 2001-2006 Wikipedia contributors (Disclaimer)

This article is licensed under the GNU Free Documentation License.

Last updated on Wednesday October 01, 2008 at 15:55:40 PDT (GMT -0700)

View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation

This article is licensed under the GNU Free Documentation License.

Last updated on Wednesday October 01, 2008 at 15:55:40 PDT (GMT -0700)

View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation

Copyright © 2015 Dictionary.com, LLC. All rights reserved.