Order of Precedence: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "config / name" to "a / b")
m (Fix Wikipedia link)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Introduction ==
<onlyinclude>
<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 --->
=== 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 {{ic|3 + 5 + 8}} will be processed as {{ic|((3 + 5) + 8)}}
* 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 29: Line 29:
* {{hl|commandName}} a
* {{hl|commandName}} a
| {{Columns|2|
| {{Columns|2|
* [[+ |+a]]
* [[+|+a]]
* [[- | -a]]
* [[-|-a]]
* [[+ | +array]]
* [[+|+array]]
* [[!_a | !b]]
* [[! a|! b]]
* [[not | not b]]
* [[not|not b]]
}}
}}
|-
|-
Line 39: Line 39:
| Hash-select operator
| Hash-select operator
|
|
* [[a_hash_b| array # index]]
* [[a hash b|array # index]]
|-
|-
| style="text-align: center" | 8
| style="text-align: center" | 8
Line 50: Line 50:
* [[Number]] multiplication, division and remainder
* [[Number]] multiplication, division and remainder
* [[atan2]]
* [[atan2]]
* [[Config]] access ([[config / name|/]])
* [[Config]] access ([[a / b|/]])
| {{Columns|2|
| {{Columns|2|
* [[a * b]]
* [[a * b]]
Line 67: Line 67:
* [[min]] and [[max]] commands
* [[min]] and [[max]] commands
| {{Columns|2|
| {{Columns|2|
* [[+ | a + b]]
* [[+|a + b]]
* [[- | a - b]]
* [[-|a - b]]
* [[+ | arr1 + arr2]]
* [[+|arr1 + arr2]]
* [[- | arr1 - arr2]]
* [[-|arr1 - arr2]]
* [[+ | str1 + str2]]
* [[+|str1 + str2]]
* [[min | a min b]]
* [[min|a min b]]
* [[max | a max b]]
* [[max|a max b]]
}}
}}
|-
|-
Line 87: Line 87:
|
|
* [[setDir]]
* [[setDir]]
* [[a_:_b |switch colon(:)]]
* [[a : b|switch colon (:)]]
|-
|-
| style="text-align: center" | 3
| style="text-align: center" | 3
Line 98: Line 98:
* [[a == b]]
* [[a == b]]
* [[a != b]]
* [[a != b]]
* [[a_greater_b| a &gt; b]]
* [[a greater b|a &gt; b]]
* [[a_less_b| a &lt; b]]
* [[a less b|a &lt; b]]
* [[a_greater=_b| a &gt;= b]]
* [[a greater= b|a &gt;= b]]
* [[a_less=_b| a &lt;= b]]
* [[a less= b|a &lt;= b]]
}}
}}
* [[config_greater_greater_name | config >> name]]
* [[config greater greater name|config >> name]]
|-
|-
| style="text-align: center" | 2
| style="text-align: center" | 2
Line 118: Line 118:
|}
|}


== Examples ==
 
=== Examples ===
 
{| class="wikitable"
{| class="wikitable"
! Input
! Input
Line 124: Line 126:
! Comment
! Comment
|-
|-
|
| <sqf>1 + 2 * 3</sqf>
1 + 2 * 3
| <sqf>1 + (2 * 3)</sqf>
|
| result equals 7, and not 9 (see also {{Link|https://en.wikipedia.org/wiki/Order_of_operations|PEMDAS}})
1 + (2 * 3)
| result equals 7, and not 9 (see also {{Wikipedia|Order of operations|PEMDAS}})
|-
|-
|
| <sqf>sleep 10 + random 20</sqf>
[[sleep]] 10 + [[random]] 20
| <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>
([[sleep]] 10) + [[random]] 20
<sqf inline>sleep (10 + random 20)</sqf> should be used instead
| {{ic|[[sleep]] 10}} will return [[Nothing]], then {{ic|+ [[random]] 20}} will be calculated but not used.<br>
{{ic|[[sleep]] (10 + [[random]] 20)}} should be used instead
|}
|}
</onlyinclude>


</onlyinclude>
[[Category:Syntax]]
[[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

  • Highest precedence means highest priority
  • Associativity is (then) done from left to right, for example 3 + 5 + 8 will be processed as ((3 + 5) + 8)
Precedence Type of Operator Examples
11

Nular operators (commands with no arguments):

  • commandName
10

Unary operators (commands with 1 argument):

  • commandName a
9 Hash-select operator
8 Power operator
7
6
5 N/A
4

Binary operators (commands with 2 arguments):

  • a commandName b
3
2 Logical and operator
1 Logical or operator


Examples

Input Process Comment
1 + 2 * 3
1 + (2 * 3)
result equals 7, and not 9 (see also PEMDAS)
sleep 10 + random 20
(sleep 10) + random 20
sleep 10 will return Nothing, then + random 20 will be calculated but not used.

sleep (10 + random 20) should be used instead