Unary operation
From Wikipedia, the free encyclopedia
In mathematics, a unary operation is an operation with only one operand (i.e. an operation with a single input). For instance, logical negation is a unary operation on truth values and squaring is a unary operation on the real numbers. Another unary operation is the factorial, n!. A unary operation (or unary operator) on a given set S is nothing but a function S → S, also called an endomorphism of S.
Unary operators (called "monadic" in APL) are also used in programming languages. For example, in the C family of languages, the following operators are unary:
- 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: sizeof(type-name)
- Cast: (type-name) cast-expression
While the above definition of a unary operation on a set S makes sense, the set must be specified. Without that, any arbitrary input can always be considered as a single entity of some, possibly quite complex, structure.