# Available Operators and Functions

Create expressions using data, operators, mathematical functions, and data type conversions.

### Operators

#### Integer Operator

Use these operators to perform simple arithmetic operations. Use them to calculate numerical values, such as "TankLevel + 60".

Operator | Expression | Description
[+] | X + Y | Add
[-] | X - Y | Subtract
[*] | X * Y | Multiply
[/] | X / Y | Divide
[%] | X % Y | Remainder of division
[()] | (X + Y)*10 |

Use the Add operator (+) to perform string concatenation. In other words, you can concatenate strings with the Add symbol, "Hello " + " " + "Billy" creates the string "Hello Billy".

#### Bitwise Operator

Operator | Expression | Description
[>>] | X >> Y | Right shift. Shifts the bits in X, to the right, by the Y number of bit positions. Preserves the sign.
[<<] | X << Y | Left shift. Shifts the bits in X, to the left, by the Y number of bit positions. Preserves the sign.
[>>>] | X >>> Y | Zero fill, right shift. Shifts the bits in X, to the right, by the Y number of bit positions, and fills in shifted bits on the left with 0s, thereby not preserving the sign.
[&] | X & Y | Returns the result of the AND operation at the bit level. If X = 0110; Y= 1100 then the result is 0100
[|] | X | Y | Returns the result of the OR operation at the bit level. If X = 0110; Y= 1100 then the result is 1110
[^] | X ^ Y | Returns the result of the XOR operation at the bit level. If X = 0110; Y= 1100 then the result is 1010
[~] | ~X | Flips the bits in the value X. If X = 0110; then the result is 1001
[!] | !X | Returns true when X is not equal.

Note:

- OR/AND/XOR/NOT always return a 32 bit unsigned integer value.
- When the input value is negative, bit shift expressions return a 32 bit integer value.
- When the input value is positive, bit shift expressions return a 32 bit unsigned integer value.

#### BOOL Output Operator

These operators compare two values. The expression returns true when the defined comparison is true. The expression returns false when the defined comparison is false. Use them to compare numerical values, such as "TankLevel > 30".

When one of the following occurs in a value, the result is undefined:

- Communication error (variable has "bad" quality)
- Accessing array element number that is out of bounds

- Divide by zero.

Operator | Expression | Description
- [&&] | X && Y | Logical AND. Note: BOOL expressions in a converter must evaluate to a boolean value. If the expression evaluates to any other data type, the value is undefined. Even though the value of one of the operands may be undefined, the resulting logical condition could evaluate to false if the other operand is false. Please see table below.
  Left operator | Right operator | Result
  undefined | undefined | undefined
  undefined | true | undefined
  undefined | false | false
  true | undefined | undefined
  false | undefined | false
- [||] | X || Y | Logical OR. Note: BOOL expressions in a converter must evaluate to a boolean value. If the expression evaluates to any other data type, the value is undefined. Even though the value of one of the operands may be undefined, the resulting logical condition could evaluate to true if the other operand is true. Please see table below.
  Left operator | Right operator | Result
  undefined | undefined | undefined
  undefined | true | true
  undefined | false | undefined
  true | undefined | true
  false | undefined | undefined
[==] | X == Y | Returns true when X is equal to Y.
[!=] | X != Y | Returns true when X is not equal to Y.
[<=] | X <= Y | Returns true when X is less than or equal to Y. Note: This operator cannot be used for BOOL variable, STRING variable, and WSTRING variable.
[>=] | X >= Y | Returns true when X is greater than or equal to Y. Note: This operator cannot be used for BOOL variable, STRING variable, and WSTRING variable.
[<] | X < Y | Returns true when X is less than Y. Note: This operator cannot be used for BOOL variable, STRING variable, and WSTRING variable.
[>] | X > Y | Returns true when X is greater than Y. Note: This operator cannot be used for BOOL variable, STRING variable, and WSTRING variable.

### Math

Method | Description
abs(a) | Returns the absolute value. parameter: integer, return: integer -or- parameter: long, return: long -or- parameter: float, return: float -or- parameter: double, return: double
acos(double a) | Returns the arc cosine. parameter: double, return: double
asin(double a) | Returns the arc sine. parameter: double, return: double
atan(double a) | Returns the arc tangent. parameter: double, return: double
atan2(double a, double b) | Returns the arc tangent of a/b. parameter a: double, parameter b: double, return: double
ceil(double a) | Returns the smallest integer that is greater than the parameter. parameter: double, return: double
cos(double a) | Returns the cosine. parameter: double, return: double
E | Base value of natural logarithms. Double precision floating point number. 2.71828182845904523545f Note: Use Math.E syntax.
exp(double a) | Returns the exponential number e (i.e. 2.718...) raised to the power of a double value. parameter: double, return: double
floor(double a) | Returns the largest integer that is less than the parameter. parameter: double, return: double
IEEEremainder(double a, double b) | Returns the remainder when parameter a is divided by parameter b. parameter a: double, parameter b: double, return: double
log(double a) | Returns the natural logarithm of the parameter. parameter: double, return: double
max(a,b) | Returns the larger of the 2 parameters. parameter a: integer, parameter b: integer, return: integer -or- parameter a: long, parameter b: long, return: long -or- parameter a: float, parameter b: float, return: float -or- parameter a: double, parameter b: double, return: double
min(a,b) | Returns the smaller of the 2 parameters. parameter a: integer, parameter b: integer, return: integer -or- parameter a: long, parameter b: long, return: long -or- parameter a: float, parameter b: float, return: float -or- parameter a: double, parameter b: double, return: double
PI | The ratio of the circumference of a circle to its diameter. 3.14159265358979323846f Note: Use Math.PI syntax.
pow(double a, double b) | Returns ab. parameter a: double, parameter b: double, return: double
random() | Returns a random number between 0.0 and 1.0. parameter: none, return: double Note: The output of this function is a floating point number between 0 and 1.
rint(double a) | Returns the closest integer to the parameter. parameter: double, return: double
round(a) | Returns the closest long for a double parameter, and the closest integer for a float parameter. parameter: double, return: long -or- parameter: float, return: integer
sin(double a) | Returns the sine of the parameter. parameter: double, return: double
sqrt(double a) | Return the square root of the parameter. parameter: double, return: double
tan(double a) | Returns the tangent of the parameter. parameter: double, return: double

### Type Conversion

Use type conversion to convert data type. The following is an example of a valid expression, where the LWORD variable is converted to SINT variable:

Type | Description
(sint) | Returns the value rounded into 8 bit signed integer.
(usint) | Returns the value rounded into 8 bit unsigned integer.
(byte) | Returns the value rounded into 8 bit unsigned integer.
(int) | Returns the value rounded into 16 bit signed integer.
(uint) | Returns the value rounded into 16 bit unsigned integer.
(word) | Returns the value rounded into 16 bit unsigned integer.
(dint) | Returns the value rounded into 32 bit signed integer.