NCalc Operators
Expressions can be combined using operators, each of which has a precedence priority. Below is the list of expression priorities in descending order:
- Primary
- Unary
- Power
- Multiplicative
- Additive
- Relational
- Bitwise
- Logical
Doc editor: The original omits
7. Bitwise
.
These operators follow the precedence rules to determine the order in which operations are performed in an expression.
Logical
Logical operators perform logical comparisons between expressions.
or
,||
and
,&&
Examples:
true or false and true
(1 == 1) || false
Theand
operator has higher priority than theor
operator, thus in the example above,false and true
is evaluated first.
Relational
Relational operators compare two values and return a boolean result.
Thein
andnot in
operators right value must be a string or IEnumerable.
=
,==
,!=
,<>
<
,<=
,>
,>=
in
,not in
Examples:
3 < 2
42 == 42
'Insert' in ('Insert', 'Update')
"Sergio" in "Sergio is at Argentina"
"Mozart" not in ("Chopin", "Beethoven", GetComposer())
945 != 202
Additive
Additive operators perform addition and subtraction.
+
,-
Examples:
1 + 2 - 3
Multiplicative
Multiplicative operators perform multiplication, division, and modulus operations.
*
,/
,%
Examples:
1 * 2 % 3
Bitwise
Bitwise operators perform bitwise operations on integers.
&
(bitwise and),|
(bitwise or),^
(bitwise xor),<<
(left shift),>>
(right shift)
Examples:
2 >> 3
Unary
Unary operators operate on a single operand.
!
,not
,-
,~
(bitwise not)
Examples:
not true
Exponential
Exponential operators perform exponentiation.
**
Examples:
2 ** 2
Primary
Primary operators include grouping of expressions, lists and direct values. Check Ncalc Values for more info.
(
,)
- values
Examples:
2 * (3 + 2)
("foo","bar", 5)
drop_database()