Search: in
Unary operation
Unary operation Encyclopedia
  Tutorials     Encyclopedia     Dictionary     Directory  
Unary_operation Email this to a friend      Unary_operation

Unary operation

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).

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.

Contents


Unary Negative and Positive

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)

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

  • 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

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.

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.

Example 1

Output: 0 1

Whereas a prefixed operation will increment the value before it has been called.

Example 2

Output: 1 2

The usage of incremental and decremental operators is usually found in For loops.

$ in the Unix shell

In Unix shell scripting (usually bash) and other utilities such as Makefiles, the "$" is a unary operator that translates the name of a variable into its contents. Many people confuse this with a sigil (as used in PHP/Perl), but it is properly a unary operator for lexical indirection, similar to the * indirection operator for pointers in C. (This is why bash only uses $ when "reading" from variables, but not when "writing" to them.)

See also

ar:????? ?????? cs:Unární operace de:Einstellige Verknüpfung et:Unaarne tehe es:Operación unaria it:Operazione unaria he:????? ??????? nl:Unaire operatie ja:???? pt:Operação unária ru:??????? ???????? sl:Eno?lena operacija sr:?????? ????????? sv:Unär operator th:?????????????????? zh:??





Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article



Related Links in Unary operation

Search for Unary operation in Tutorials
Search for Unary operation in Encyclopedia
Search for Unary operation in Dictionary
Search for Unary operation in Open Directory
Search for Unary operation in Store
Search for Unary operation in PriceGig



Help build the largest human-edited directory on the web.
Submit a Site - Open Directory Project - Become an Editor

Advertisement

Advertisement



Unary operation
Unary_operation top Unary_operation

Home - Add TutorGig to Your Site - Disclaimer

©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement