Operators

From SysCAD Documentation

Jump to: navigation, search

Navigation: PGMs


Contents

Operators Summary

See also Operator Precedence.

Arithmetic(Arithmetic Operators) Logical (Logical Operators)
+ Addition AND Logical AND
- Subtraction OR Logical OR
* Multiplication XOR Logical Exclusive OR
/ Division NOT Logical NOT
^ Power


Comparison (Comparison Operators) Bitwise (Bitwise Operators)
< Less Than BAND Bitwise AND
<= Less Than or Equal To BOR Bitwise OR
> Greater Than BXOR Bitwise Exclusive OR
>= Greater Than or Equal To BNOT Bitwise NOT
== Equal To
<> Not Equal To
!= Not Equal To


Miscellaneous

( ) Round Brackets ( )

Operator Precedence

The following table lists the precedence of each operator in descending order.

The lines separate the different levels of operator precedence.

Where consecutive operators occur having the SAME precedence, then they are carried out from left to right

The Association column determines the order in which the operands are operated upon.


Symbol Name or Meaning Association
Highest Precedence
Right to Left
NOT Logical NOT
BNOT Bitwise NOT
- Unary minus
+ Unary plus
Left to Right
^ Power
Left to Right
* Multiply
/ Divide
Left to Right
+ Add
- Subtract
Left to Right
< Less than
<= Less than or equal
> Greater than
>= Greater than or equal
Left to Right
== Equal
<> or != Not equal
Left to Right
BAND Bitwise AND
Left to Right
BXOR Bitwise exclusive
OR
Left to Right
BOR Bitwise OR
Left to Right
AND Logical AND
Left to Right
XOR Logical exclusive
OR
Left to Right
OR Logical OR
Right to Left
= Assignment
Lowest Precedence

Arithmetic Operators

Addition Operator : +

operand1 + operand2
This adds operand2 to operand1.
The operands must be numeric variables.


Subtraction Operator : -

operand1 - operand2
This subtracts operand2 from operand1.
The operands must be numeric variables.


Multiplication Operator : *

operand1 * operand2
This multiplies operand2 by operand1.
The operands must be numeric variables.


Division Operator : /

operand1 / operand2
This divides operand1 by operand2.
The operands must be numeric variables.
NB : Division by zero will result in an error as it is undefined. Please see How do I avoid a 'Divide by Zero' error? for ways of avoiding this error when using measured variables.

See also Div and Mod.


Power Operator : ^

operand1 ^ operand2
This raises operand1 to the power operand2.
The operands must be numeric variables.
NB : Invalid operations (eg 0^0.5 or -3^0.5) will result in an error as it is undefined.

Comparison Operators

These operators can be used on all numerical variables.

They are used to determine the validity of the given comparison.

If the comparison is TRUE, then the value of the expression is not equal to zero.

If the comparison is FALSE, then the value of the expression is equal to zero.


Operator Comparison being tested
< Is the first operand less than the second operand
<= Is the first operand less than or equal to the second operand
> Is the first operand greater than the second operand
>= Is the first operand greater than or equal to the second operand
== Is the first operand equal to the second operand
<> Is the first operand not equal to the second operand
 != Is the first operand not equal to the second operand

Logical Operators

The logical-AND operator, the logical-OR operator and the logical-Exclusive OR operator can used on their own or in conjunction with the comparison operators to combine multiple conditions.

Logical-AND Operator: AND

expression AND expression
If both of the operands are non zero, then the logical-AND operator returns TRUE i.e. a non zero value, otherwise it returns a value of FALSE or zero.
The first operand is completely evaluated, and only if it is evaluated to be TRUE i.e. a non zero value, is the second operand evaluated.


Logical OR Operator: OR

expression OR expression
If either or both of the operands are non zero, then the logical-OR operator returns TRUE i.e. a non zero value, otherwise it returns a value of FALSE or zero.
The first operand is completely evaluated, and only if it is evaluated to be FALSE or zero, is the second operand evaluated.


Logical-Exclusive OR Operator: XOR

expression XOR expression
If either, but not both, of the operands are non zero, then the logical-XOR operator returns TRUE i.e. a non zero value, otherwise it returns a value of FALSE or zero.
Both operands are completely evaluated.


Logical-NOT Operator: NOT

NOT expression
If the operand is TRUE or non zero, then the logical-NOT operator returns FALSE or zero.
If the operand is FALSE or zero, then the logical-NOT operator returns TRUE or non zero.

Bitwise Operators

Bitwise -AND Operator: BAND

operand1 BAND operand2
Each bit of operand1 is compared with the corresponding bit of operand2.
If both of the bits are 1 the corresponding result bit is set to 1.
Otherwise the corresponding result bit is set to 0.


Bitwise -OR Operator: BOR

operand1 BOR operand2
Each bit of operand1 is compared with the corresponding bit of operand2.
If either of the bits are 1 the corresponding result bit is set to 1.
Otherwise the corresponding result bit is set to 0.


Bitwise-Exclusive OR Operator: BXOR

operand1 BXOR operand2
Each bit of operand1 is compared with the corresponding bit of operand2.
If either (but not both) of the bits are 1 then the corresponding result bit is set to 1.
Otherwise the corresponding result bit is set to 0.


Bitwise-NOT Operator: BNOT

BNOT operand
This produces a bitwise complement of operand :
all the bits in operand that were 1 are set to 0 and
all the bits in operand that were 0 are set to 1.

Round Brackets ( )

  1. Used in arithmetic expressions to ensure that certain operations are performed before other operations, regardless of the operator precedence.
    ...3 * (4 + 2) - ...
    In this case : 2 is added to 4 BEFORE the result is multiplied by 3.
  2. Used in conditional expressions to ensure that certain conditions are complied with before other conditions.
    ((variable1 > 5) AND (variable2 < variable3)) OR NOT variable4
    In this case, both variable1and variable2 must comply with the specified criteria or variable4 must be false, for this condition to be true.
  3. Used in function declarations to contain the function arguments and by the function calls to contain the function parameters.
Personal tools
Document Sections