Order of Precedence: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Introduction == Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression....") |
Lou Montana (talk | contribs) m (Fix Wikipedia link) |
||
(14 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<onlyinclude> | |||
Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression. | Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression. | ||
=== Precedence Overview === <!--- Level 3 because it's transcluded into Operators page ---> | |||
{{Feature | Informative | | {{Feature | Informative | | ||
* Highest precedence means highest priority | * Highest precedence means highest priority | ||
* Associativity is (then) done from left to right, for example | * Associativity is (then) done from left to right, for example <sqf inline>3 + 5 + 8</sqf> will be processed as <sqf inline>((3 + 5) + 8)</sqf> | ||
}} | }} | ||
Line 16: | Line 18: | ||
| | | | ||
Nular operators (commands with no arguments): | Nular operators (commands with no arguments): | ||
* | * {{hl|commandName}} | ||
| | | | ||
* [[Variables]] | * [[Variables]] | ||
Line 25: | Line 27: | ||
| | | | ||
Unary operators (commands with 1 argument): | Unary operators (commands with 1 argument): | ||
* | * {{hl|commandName}} a | ||
| | | {{Columns|2| | ||
* [[+ |+a]] | * [[+|+a]] | ||
* [[- | -a]] | * [[-|-a]] | ||
* [[+|+array]] | |||
* [[+ | +array]] | * [[! a|! b]] | ||
* [[not|not b]] | |||
* [[! | }} | ||
* [[not | not b]] | |||
|- | |- | ||
| style="text-align: center" | 9 | | style="text-align: center" | 9 | ||
| Hash-select operator | | Hash-select operator | ||
| | | | ||
* [[ | * [[a hash b|array # index]] | ||
|- | |- | ||
| style="text-align: center" | 8 | | style="text-align: center" | 8 | ||
Line 49: | Line 50: | ||
* [[Number]] multiplication, division and remainder | * [[Number]] multiplication, division and remainder | ||
* [[atan2]] | * [[atan2]] | ||
* [[Config]] access ([[ | * [[Config]] access ([[a / b|/]]) | ||
| | | {{Columns|2| | ||
* [[a * b]] | * [[a * b]] | ||
* [[a / b]] | * [[a / b]] | ||
* [[a % b]] | * [[a % b]] | ||
* [[mod | a mod b]] | * [[mod | a mod b]] | ||
* [[a / b]] | |||
* [[ | |||
* [[atan2| a atan2 b]] | * [[atan2| a atan2 b]] | ||
}} | |||
|- | |- | ||
| style="text-align: center" | 6 | | style="text-align: center" | 6 | ||
Line 66: | Line 66: | ||
* [[String]] addition | * [[String]] addition | ||
* [[min]] and [[max]] commands | * [[min]] and [[max]] commands | ||
| | | {{Columns|2| | ||
* [[+ | a + b]] | * [[+|a + b]] | ||
* [[- | a - b]] | * [[-|a - b]] | ||
* [[+|arr1 + arr2]] | |||
* [[+ | arr1 + arr2]] | * [[-|arr1 - arr2]] | ||
* [[- | arr1 - arr2]] | * [[+|str1 + str2]] | ||
* [[min|a min b]] | |||
* [[+ | str1 + str2]] | * [[max|a max b]] | ||
}} | |||
* [[min | a min b]] | |||
* [[max | a max b]] | |||
|- | |- | ||
| style="text-align: center" | 5 | | style="text-align: center" | 5 | ||
Line 86: | Line 84: | ||
| | | | ||
Binary operators (commands with 2 arguments): | Binary operators (commands with 2 arguments): | ||
* a | * a {{hl|commandName}} b | ||
| | | | ||
* [[setDir]] | * [[setDir]] | ||
* [[ | * [[a : b|switch colon (:)]] | ||
|- | |- | ||
| style="text-align: center" | 3 | | style="text-align: center" | 3 | ||
Line 97: | Line 95: | ||
* [[Config]] access ([[config greater greater name|>>]]) | * [[Config]] access ([[config greater greater name|>>]]) | ||
| | | | ||
{{Columns|2| | |||
* [[a == b]] | * [[a == b]] | ||
* [[a != b]] | * [[a != b]] | ||
* [[ | * [[a greater b|a > b]] | ||
* [[ | * [[a less b|a < b]] | ||
* [[ | * [[a greater= b|a >= b]] | ||
* [[ | * [[a less= b|a <= b]] | ||
}} | |||
* [[ | * [[config greater greater name|config >> name]] | ||
|- | |- | ||
| style="text-align: center" | 2 | | style="text-align: center" | 2 | ||
Line 119: | Line 118: | ||
|} | |} | ||
[[Category: | |||
=== Examples === | |||
{| class="wikitable" | |||
! Input | |||
! Process | |||
! Comment | |||
|- | |||
| <sqf>1 + 2 * 3</sqf> | |||
| <sqf>1 + (2 * 3)</sqf> | |||
| result equals 7, and not 9 (see also {{Link|https://en.wikipedia.org/wiki/Order_of_operations|PEMDAS}}) | |||
|- | |||
| <sqf>sleep 10 + random 20</sqf> | |||
| <sqf>(sleep 10) + random 20</sqf> | |||
| <sqf inline>sleep 10</sqf> will return [[Nothing]], then <sqf inline>+ random 20</sqf> will be calculated but not used.<br> | |||
<sqf inline>sleep (10 + random 20)</sqf> should be used instead | |||
|} | |||
</onlyinclude> | |||
[[Category:Syntax]] |
Latest revision as of 23:52, 23 February 2023
Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression.
Precedence Overview
Precedence | Type of Operator | Examples |
---|---|---|
11 |
Nular operators (commands with no arguments):
|
|
10 |
Unary operators (commands with 1 argument):
|
|
9 | Hash-select operator | |
8 | Power operator | |
7 | ||
6 | ||
5 | N/A | |
4 |
Binary operators (commands with 2 arguments):
|
|
3 | ||
2 | Logical and operator | |
1 | Logical or operator |
Examples
Input | Process | Comment |
---|---|---|
result equals 7, and not 9 (see also PEMDAS) | ||
sleep 10 will return Nothing, then + random 20 will be calculated but not used. |