forked from ncalc/ncalc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
21 changed files
with
463 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,115 @@ | ||
# Operators | ||
|
||
Expressions can be combined using operators. Each operator as a precedence priority. Here is the list of those expression's priority. | ||
1. primary | ||
2. unary | ||
3. power | ||
4. multiplicative | ||
5. additive | ||
6. relational | ||
7. logical | ||
Expressions can be combined using operators, each of which has a precedence priority. Below is the list of expression priorities in descending order: | ||
|
||
1. Primary | ||
2. Unary | ||
3. Power | ||
4. Multiplicative | ||
5. Additive | ||
6. Relational | ||
7. Logical | ||
|
||
These operators follow the precedence rules to determine the order in which operations are performed in an expression. | ||
|
||
## Logical | ||
|
||
These operators can do some logical comparison between other expressions: | ||
Logical operators perform logical comparisons between expressions. | ||
|
||
* or, || | ||
* and, && | ||
* `or`, `||` | ||
* `and`, `&&` | ||
|
||
Examples: | ||
``` | ||
true or false and true | ||
true or false and true | ||
(1 == 1) || false | ||
``` | ||
|
||
The **and** operator has more priority than the **or**, thus in the example above, **false and true** is evaluated first. | ||
The `and` operator has higher priority than the `or` operator, thus in the example above, `false and true` is evaluated first. | ||
|
||
## Relational | ||
|
||
* =, ==, !=, <> | ||
* <, <=, >, >= | ||
Relational operators compare two values and return a boolean result. | ||
The `in` and `not in` operators right value must be a <xref:string> or <xref:System.Collections.IEnumerable>. | ||
|
||
* `=`, `==`, `!=`, `<>` | ||
* `<`, `<=`, `>`, `>=` | ||
* `in`, `not in` | ||
|
||
Examples: | ||
``` | ||
1 < 2 | ||
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. | ||
|
||
* `+`, `-` | ||
|
||
Example: | ||
``` | ||
1 + 2 - 3 | ||
1 + 2 - 3 | ||
``` | ||
|
||
## Multiplicative | ||
|
||
* *, /, % | ||
Multiplicative operators perform multiplication, division, and modulus operations. | ||
|
||
* `*`, `/`, `%` | ||
|
||
Example: | ||
``` | ||
1 * 2 % 3 | ||
1 * 2 % 3 | ||
``` | ||
|
||
## Bitwise | ||
|
||
* & (bitwise and), | (bitwise or), ^(bitwise xor), << (left shift), >>(right shift) | ||
Bitwise operators perform bitwise operations on integers. | ||
|
||
* `&` (bitwise and), `|` (bitwise or), `^` (bitwise xor), `<<` (left shift), `>>` (right shift) | ||
|
||
Example: | ||
``` | ||
2 >> 3 | ||
2 >> 3 | ||
``` | ||
|
||
## Unary | ||
|
||
* !, not, -, ~ (bitwise not) | ||
Unary operators operate on a single operand. | ||
|
||
* `!`, `not`, `-`, `~` (bitwise not) | ||
|
||
Example: | ||
``` | ||
not true | ||
not true | ||
``` | ||
|
||
## Exponential | ||
|
||
* ** | ||
Exponential operators perform exponentiation. | ||
|
||
* `**` | ||
|
||
Example: | ||
``` | ||
2 ** 2 | ||
2 ** 2 | ||
``` | ||
|
||
|
||
## Primary | ||
|
||
* (, ) | ||
Primary operators include grouping of expressions, lists and direct values. Check [Values](values.md) for more info. | ||
|
||
* `(`, `)` | ||
* values | ||
|
||
Examples: | ||
``` | ||
2 * ( 3 + 2 ) | ||
2 * (3 + 2) | ||
("foo","bar", 5) | ||
drop_database() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.