Difference between revisions of "SHIP:Sail:Operators"

From Serious Documentation
Jump to: navigation, search
(Created page with "The following standard mathematical operators are available in Sail, listed in precedence order from first to last. Exceptions from C/Java are noted. {| class="wikitable" sty...")
 
(See Also)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The following standard mathematical operators are available in Sail, listed in precedence order from first to last. Exceptions from C/Java are noted.
+
The following standard mathematical operators are available in Sail, listed in precedence order from first to last.  
  
 
{| class="wikitable" style="width:75%;margin: 1em auto 1em auto;"
 
{| class="wikitable" style="width:75%;margin: 1em auto 1em auto;"
Line 7: Line 7:
 
! width="5%" align="center" | Group
 
! width="5%" align="center" | Group
 
! width="15%" align="center" | Operator(s)
 
! width="15%" align="center" | Operator(s)
! width="70%" align="left" | Description
+
! width="45%" align="left" | Description
! width="15%" align="left" | Order
+
! width="35%" align="left" | Order
 
|-
 
|-
|1
+
|align="center"|1
|.
+
|align="center"|.
 
|Identifier qualification
 
|Identifier qualification
 
|rowspan=2|Left-to-right
 
|rowspan=2|Left-to-right
 
|-
 
|-
|rowspan=1|2
+
|align="center"|2
|<nowiki>++ --</nowiki>
+
|align="center"|<nowiki>++</nowiki>&#160;&#160;<nowiki>--</nowiki><br>()
()
+
|Post-increment/decrement<br>Function call
|Post-increment/decrement
 
Function call
 
 
|-
 
|-
|rowspan=1|3
+
|align="center"|3
|<nowiki>++ --</nowiki>
+
|align="center"|<nowiki>++</nowiki>&#160;&#160;<nowiki>--</nowiki><br><nowiki>+ -</nowiki><br><nowiki>!</nowiki>&#160;&#160;<nowiki>~</nowiki>
<nowiki>+ -</nowiki>
+
|Pre-increment/decrement<br>Unary plus/minus<br>Logical/Bitwise NOT
<nowiki>! ~</nowiki>
 
|Pre-increment/decrement
 
Logical/Bitwise NOT
 
 
|Right-to-left
 
|Right-to-left
 
|-
 
|-
|rowspan=1|4
+
|align="center"|4
|* / %||Multiplication, Division, Modulus
+
|align="center"|<nowiki>*</nowiki>&#160;&#160;<nowiki>/</nowiki>&#160;&#160;<nowiki>%</nowiki>
 +
|Multiplication, Division, Modulus
 
|rowspan=10|Left-to-Right
 
|rowspan=10|Left-to-Right
 
|-
 
|-
|+ -||Addition, Subtraction
+
|align="center"|5
 +
|align="center"|<nowiki>+</nowiki><br><nowiki>-</nowiki>
 +
|{{†}}Addition<br>Subtraction
 
|-
 
|-
|<< >>||Bitwise left, right shift
+
|align="center"|6
 +
|align="center"|<nowiki><<</nowiki>&#160;&#160;<nowiki>>></nowiki>
 +
|Bitwise left, right shift
 +
|-
 +
|align="center"|7
 +
|align="center"|&lt;&#160;&#160;&lt;<nowiki>=</nowiki><br>&gt;&#160;&#160;&gt;<nowiki>=</nowiki>
 +
|{{†}}Less than, {{†}}Less than or equal<br>{{†}}Greater than, {{†}}Greater than or equal
 +
|-
 +
|align="center"|8
 +
|align="center"|<nowiki>==</nowiki>&#160;&#160;<nowiki>!=</nowiki>
 +
|{{†}}Equal, {{†}}Not equal
 +
|-
 +
|align="center"|9
 +
|align="center"|<nowiki>&</nowiki>
 +
|Bitwise AND
 +
|-
 +
|align="center"|10
 +
|align="center"|<nowiki>^</nowiki>
 +
|Bitwise XOR
 +
|-
 +
|align="center"|11
 +
|align="center"|<nowiki>|</nowiki>
 +
|Bitwise OR
 +
|-
 +
|align="center"|12
 +
|align="center"|<nowiki>&&</nowiki>
 +
|Logical AND
 +
|-
 +
|align="center"|13
 +
|align="center"|<nowiki>||</nowiki>
 +
|Logical OR
 +
|-
 +
|align="center"|14
 +
|align="center"|<nowiki>:?</nowiki>
 +
|Ternary Conditional
 +
|Right-to-Left; Expression between <nowiki>?</nowiki> and ? always parsed as if parenthesized.
 +
|-
 +
|align="center"|15
 +
|align="center"|<nowiki>=</nowiki><br><nowiki>+=</nowiki><br><nowiki>-=</nowiki><br><nowiki>*=</nowiki>&#160;&#160;<nowiki>/=</nowiki>&#160;&#160;<nowiki>%=</nowiki><br><nowiki><<=</nowiki>&#160;&#160;<nowiki>>>=</nowiki><br><nowiki>&=</nowiki>&#160;&#160;<nowiki>^=</nowiki>&#160;&#160;<nowiki>|=</nowiki>
 +
|{{†}}Assignment<br>{{†}}Add-assign<br>Subtract-assign<br>Multiply-, Divide-, and Modulus-assign<br>Bitwise left, right shift-assign<br>Bitwise AND, XOR, OR assign
 +
|Right-to-Left
 
|}
 
|}
 +
{{†}}These operators also can be used with the {{DataType|String}} data type.
 +
== See Also ==
 +
* [[SHIP:Data_Types|Data Types]]
 +
* [[SHIP:Node|Object Nodes, Properties, and Scope]]
 +
<!-- * [[SHIP:Sail:Operators|Operators]] -->
 +
* [[SHIP:Sail:Functions|Built-in Functions]]
  
 
+
[[Category:SHIPSail]]
6 < <= For relational operators < and ≤ respectively
 
> >= For relational operators > and ≥ respectively
 
7 == != For relational = and ≠ respectively
 
8 & Bitwise AND
 
9 ^ Bitwise XOR (exclusive or)
 
10 | Bitwise OR (inclusive or)
 
11 && Logical AND
 
12 || Logical OR
 
13[note 1] ?: Ternary conditional[note 2] Right-to-Left
 
14 = Simple assignment
 
+= −= Assignment by sum and difference
 
*= /= %= Assignment by product, quotient, and remainder
 
<<= >>= Assignment by bitwise left shift and right shift
 
&= ^= |= Assignment by bitwise AND, XOR, and OR
 
15 , Comma Left-to-right
 

Latest revision as of 17:11, 3 November 2016

The following standard mathematical operators are available in Sail, listed in precedence order from first to last.

SHIPSail Operators and Precedence
Group Operator(s) Description Order
1 . Identifier qualification Left-to-right
2 ++  --
()
Post-increment/decrement
Function call
3 ++  --
+ -
!  ~
Pre-increment/decrement
Unary plus/minus
Logical/Bitwise NOT
Right-to-left
4 *  /  % Multiplication, Division, Modulus Left-to-Right
5 +
-
Addition
Subtraction
6 <<  >> Bitwise left, right shift
7 <  <=
>  >=
Less than, Less than or equal
Greater than, Greater than or equal
8 ==  != Equal, Not equal
9 & Bitwise AND
10 ^ Bitwise XOR
11 | Bitwise OR
12 && Logical AND
13 || Logical OR
14 :? Ternary Conditional Right-to-Left; Expression between ? and ? always parsed as if parenthesized.
15 =
+=
-=
*=  /=  %=
<<=  >>=
&=  ^=  |=
Assignment
Add-assign
Subtract-assign
Multiply-, Divide-, and Modulus-assign
Bitwise left, right shift-assign
Bitwise AND, XOR, OR assign
Right-to-Left

These operators also can be used with the String data type.

See Also