Difference between revisions of "MC-Basic Operators"

From SoftMC-Wiki
Jump to: navigation, search
m (Arithmetic Operators)
 
(21 intermediate revisions by 4 users not shown)
Line 61: Line 61:
 
|Equality
 
|Equality
 
|align="center"|=
 
|align="center"|=
|align="center"|1
+
|align="center"|6
 
|-
 
|-
 
|Inequality
 
|Inequality
 
|align="center"|<>
 
|align="center"|<>
|align="center"|1
+
|align="center"|6
 
|-
 
|-
 
|Less than
 
|Less than
 
|align="center"|<
 
|align="center"|<
|align="center"|1
+
|align="center"|6
 
|-
 
|-
 
|Greater than
 
|Greater than
 
|align="center"|>
 
|align="center"|>
|align="center"|1
+
|align="center"|6
 
|-
 
|-
 
|Less than or equal to
 
|Less than or equal to
 
|align="center"|<=
 
|align="center"|<=
|align="center"|1
+
|align="center"|6
 
|-
 
|-
 
|Greater than or equal to
 
|Greater than or equal to
 
|align="center"|>=
 
|align="center"|>=
|align="center"|1
+
|align="center"|6
 
|}
 
|}
  
Line 97: Line 97:
 
|Complement
 
|Complement
 
|align="center"|NOT
 
|align="center"|NOT
|align="center"|1
+
|align="center"|7
 
|-
 
|-
 
|And
 
|And
 
|align="center"|AND
 
|align="center"|AND
|align="center"|2
+
|align="center"|8
 
|-
 
|-
 
|Or
 
|Or
 
|align="center"|OR
 
|align="center"|OR
|align="center"|3
+
|align="center"|9
 
|-
 
|-
 
|Exclusive Or
 
|Exclusive Or
 
|align="center"|XOR
 
|align="center"|XOR
|align="center"|4
+
|align="center"|10
 
|}
 
|}
 
   
 
   
== Bit-wise Operators ==
+
== Bitwise Operators ==
 
Bitwise operators perform bit manipulations on integer operands only.  
 
Bitwise operators perform bit manipulations on integer operands only.  
 
The result of the operation is a Long.
 
The result of the operation is a Long.
Line 121: Line 121:
 
!Symbol
 
!Symbol
 
!Relative Precedence
 
!Relative Precedence
 +
|-
 +
|Shift left
 +
|align="center"|[[MC-Basic:SHL|SHL]]
 +
|align="center"|4
 +
|-
 +
|Shift right
 +
|align="center"|[[MC-Basic:SHR|SHR]]
 +
|align="center"|4
 
|-  
 
|-  
 
|Bitwise complement
 
|Bitwise complement
 
|align="center"|BNOT
 
|align="center"|BNOT
|align="center"|1
+
|align="center"|11
 
|-
 
|-
|Bitwise And
+
|Bitwise AND
 
|align="center"|BAND
 
|align="center"|BAND
|align="center"|2
+
|align="center"|12
 
|-
 
|-
|Bitwise Or
+
|Bitwise OR
 
|align="center"|BOR
 
|align="center"|BOR
|align="center"|3
+
|align="center"|13
 
|-
 
|-
|Bitwise Exclusive Or
+
|Bitwise Exclusive OR
 
|align="center"|BXOR
 
|align="center"|BXOR
|align="center"|4
+
|align="center"|14
 
|}
 
|}
 
   
 
   
Line 142: Line 150:
  
  
[[Category:Axystems:MC-Basic]]
+
[[Category:MC-Basic|Operators]]
 
[[Category:Control:Offline]]
 
[[Category:Control:Offline]]

Latest revision as of 14:42, 28 May 2014

The tables shown below list the different types of operators, and their relative precedence. Arithmetic operators have the highest precedence, followed by Relational, Logical and Bit-wise operators. The relative precedence of the operators within each group is noted in the tables. Parentheses may be used to force a different order of expression processing because parentheses have the highest precedence. The “+” operator can be used to concatenate strings, and the “=” operator can be used to copy strings. The other operators have no applicability with strings.

The “=” operator can also be utilized to copy the entire values of an array to another array (matching in size and number of dimensions) through a single assignment statement. Other operators have no applicability with whole arrays.

Arithmetic Operators

Operation Symbol Relative Precedence
Exponentiation ^ 1
Negation/N/A minus - 2
Multiplication * 3
Division / 3
Modulus MOD 4
Addition + 5
Subtraction - 5

Relational Operators

Relational operators provide a method whereby two values may be compared. The result of the comparison is either TRUE (1) or FALSE (0). The operators are listed below; all Relational Operators have the same level of precedence, and relational operators have lower precedence than arithmetic operators. Relational operators may be used with any type of variable or value, including strings. String comparisons are made character-by-character, starting with the first character in each string, thus the string “de” is greater than the string “abc”. Character comparisons are made according to the value of the ASCII character codes for the respective characters.

Operation Symbol Relative Precedence
Equality = 6
Inequality <> 6
Less than < 6
Greater than > 6
Less than or equal to <= 6
Greater than or equal to >= 6

Logical Operators

Logical operators perform tests on multiple relations, and return a True (nonzero) or False (zero) value to be used in making a decision. Logical operators have lower precedence than Relational operators. They may be used on integer operands only (including the results of relational expressions).

Operation Symbol Relative Precedence
Complement NOT 7
And AND 8
Or OR 9
Exclusive Or XOR 10

Bitwise Operators

Bitwise operators perform bit manipulations on integer operands only. The result of the operation is a Long.

Operation Symbol Relative Precedence
Shift left SHL 4
Shift right SHR 4
Bitwise complement BNOT 11
Bitwise AND BAND 12
Bitwise OR BOR 13
Bitwise Exclusive OR BXOR 14