Language › Operators
Operators
Hover's operator set is C's, with one addition (** for power) and one restriction: bitwise operators are integers-only, enforced at compile time.
Arithmetic
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| ** | Power |
| % | Modulo |
Bitwise & integer operators
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise XOR |
| << | Left shift |
| >> | Right shift |
| ~ | Bitwise NOT (unary) |
Integers only. Applying a bitwise operator to a double or float is a semantic error at compile time, not a silent coercion.
& and * are overloaded by position: between two operands they are bitwise AND and multiplication; in front of a single operand with nothing to their left they are address-of and dereference. See Pointers.
Comparison
Comparisons return 1.0 or 0.0 — there's no separate boolean type.
| == | Equal |
| != | Not equal |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal |
| <= | Less than or equal |
Logical
| && | Logical AND |
| || | Logical OR |
| ! | Logical NOT |
Precedence
Highest to lowest:
| f() a[] | Function call, array subscript |
| -x !x ~x | Unary minus, logical NOT, bitwise NOT |
| &x *x | Address-of, dereference (unary) |
| ** | Power |
| * / % | Multiplicative |
| + - | Additive |
| << >> | Bitwise shift |
| > < >= <= | Relational |
| == != | Equality |
| & | Bitwise AND |
| ^ | Bitwise XOR |
| | | Bitwise OR |
| && | Logical AND |
| || | Logical OR |