# Expression

The expression block returns result of expression. In the following examples, the number of decimal places is 2.

Hide Show

1. cast
2. abs (a)
3. acos (double a)
4. asin (double a)
5. atan (double a)
6. atan2 (double a, double b)
7. ceil (double a)
8. cos (double a)
9. E
10. exp (double a)
11. floor (double a)
12. IEEEremainder (double a, double b)
13. log (double a)
14. max (a,b)
15. min (a,b)
16. PI
17. pow (double a, double b)
18. random
19. rint (double a)
20. round (a)
21. sin (double a)
22. sqrt (double a)
23. tan (double a)

## cast

##### Block

##### Text

'$Math.cast($Enums.CastDataType.SINT, EXPRESSION)'

SINT | Returns the value rounded to a 8 bit signed integer.
USINT | Returns the value rounded to a 8 bit unsigned integer.
BYTE | Returns the value rounded to a 8 bit unsigned integer.
INT | Returns the value rounded to a 16 bit signed integer.
UINT | Returns the value rounded to a 16 bit unsigned integer.
WORD | Returns the value rounded to a 16 bit unsigned integer.
DINT | Returns the value rounded to a 32 bit signed integer.

(Example 1)

Round down to the closest integer: If Var1 is 1.9, the output is 1.

##### Block

##### Text

'$Math.cast($Enums.CastDataType.WORD, Var1)'

(Example 2)

If the variable value exceeds the range of the specified data type, the portion of the exceeded value loops between the minimum and maximum limits: If Var1 is 200, the output is -56.

##### Block

##### Text

'Math.cast($Enums.CastDataType.SINT, Var1)'

## abs (a)

Returns the absolute value of the parameter.

parameter data type: integer, long, float, double.

Return value data type: Same as the set parameter data type.

##### Block

##### Text

'$Math.abs(EXPRESSION)'

(Example)

When Var1 is -3, output is 3.

##### Block

##### Text

'$Math.abs(Var1)'

## acos (double a)

Returns the arc cosine value (radians) of the parameter (ratio of 2 sides).

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.acos(EXPRESSION)'

(Example)

When Var1 is 1, output is 0.

##### Block

##### Text

'$Math.acos(Var1)'

## asin (double a)

Returns the arc sine value (radians) of the parameter (ratio of 2 sides).

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.asin(EXPRESSION)'

(Example)

When Var1 is 1, output is 1.57.

##### Block

##### Text

'$Math.asin(Var1)'

## atan (double a)

Return the arc tangent value (radians) of the parameter (ratio of 2 sides).

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.atan(EXPRESSION)'

(Example)

When Var1 is 1, output is 0.79.

##### Block

##### Text

'$Math.atan(Var1)'

## atan2 (double a, double b)

Returns the arc tangent value (radians) of the parameters (base "b" and height "a").

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.atan2(EXPRESSION1, EXPRESSION2)'

(Example)

When Var1 is 2 and Var2 is 1, output is 1.11.

##### Block

##### Text

'$Math.atan2(Var1, Var2)'

## ceil (double a)

Returns the smallest integer that is greater than the parameter.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.ceil(EXPRESSION)'

(Example)

When Var1 is 1.2, output is 2.

##### Block

##### Text

'$Math.ceil(Var1)'

## cos (double a)

Return the cosine value (ratio of 2 sides) of the parameter (radians).

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.cos(EXPRESSION)'

(Example)

When Var1 is 1, output is 0.54.

##### Block

##### Text

'$Math.cos(Var1)'

## E

Base value of natural logarithms. Double precision floating point number. 2.71828182845904523545f

##### Block

##### Text

'$Math.E()'

Note: Use Math.E syntax.

## exp (double a)

Returns the exponential number e (i.e. 2.718...) to the power of the double value.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.exp(EXPRESSION)'

(Example)

When Var1 is 1, the output is 2.718..(e1).

##### Block

##### Text

'$Math.exp(Var1)'

## floor (double a)

Returns the largest integer that is less than the parameter.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.floor(EXPRESSION)'

(Example)

When Var1 is 1.5, output is 1.

##### Block

##### Text

'$Math.floor(Var1)'

## IEEEremainder (double a, double b)

Returns the remainder when parameter a is divided by parameter b.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.IEEEremainder(EXPRESSION1, EXPRESSION2)'

(Example)

When Var1 is 11 and Var2 is 3, the output is -1.

##### Block

##### Text

'$Math.IEEEremainder(Var1, Var2)'

## log (double a)

Returns the natural logarithm of the parameter.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.log(EXPRESSION)'

(Example)

When Var1 is 2.72, the output is 1.

##### Block

##### Text

'$Math.log(Var1)'

## max (a,b)

Returns the larger of the 2 parameters. If both parameters are negative, the one with the smaller absolute value is returned.

Parameter data type: integer, long, float, double

Use the same data type for the parameter.

Return value data type: The same data type as the parameters.

##### Block

##### Text

'$Math.max(EXPRESSION1, EXPRESSION2)'

(Example)

When Var1 is 10 and Var2 is 2, the output is 10.

##### Block

##### Text

'$Math.max(Var1, Var2)'

## min (a,b)

Returns the smaller of the 2 parameters. If both parameters are negative, the one with the greater absolute value is returned.

Parameter data type: integer, long, float, double

Use the same data type for the parameter.

Return value data type: The same data type as the parameters.

##### Block

##### Text

'$Math.min(EXPRESSION1, EXPRESSION2)'

(Example)

When Var1 is 10 and Var2 is 2, the output is 2.

##### Block

##### Text

'$Math.min(Var1, Var2)'

## PI

The ratio of the circumference of a circle to its diameter.

3.14159265358979323846f

##### Block

##### Text

'$Math.PI()'

Note: Use Math.PI syntax.

## pow (double a, double b)

Returns ab.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.pow(EXPRESSION1, EXPRESSION2)'

(Example)

When Var1 is 2 and Var2 is 3, the output is 8.

##### Block

##### Text

'$Math.pow(Var1, Var2)'

## random

Returns a random number between 0.0 and 1.0.

Return value data type: double

##### Block

##### Text

'$Math.Random()'

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 data type: double

Return value data type: double

##### Block

##### Text

'$Math.rint(EXPRESSION)'

Note: The data types of the values used for parameters and return values are different for rint and round. Use each in accordance with the data type of the value in the expression.

(Example)

When Var1 is 1.4, the output is 1. And when Var1 is 1.5, the output is 2.

##### Block

##### Text

'$Math.rint(Var1)'

## round (a)

Returns the closest long for a double parameter, and the closest integer for a float parameter.

Parameter data type: double

Return value data type: long

or

Parameter data type: float

Return value data type: integer

##### Block

##### Text

'$Math.round(EXPRESSION)'

Note: The data types of the values used for parameters and return values are different for rint and round. Use each in accordance with the data type of the value in the expression.

(Example)

When Var1 is 1.4, the output is 1. And when Var1 is 1.5, the output is 2.

##### Block

##### Text

'$Math.round(Var1)'

## sin (double a)

Return the sine value (ratio of 2 sides) of the parameter (radians).

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.sin(EXPRESSION)'

(Example)

When Var1 is 1, output is 0.84.

##### Block

##### Text

'$Math.sin(Var1)'

## sqrt (double a)

Returns the square root of the parameter.

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.sqrt(EXPRESSION)'

(Example)

When Var1 is 9, the output is 3.

##### Block

##### Text

'$Math.sqrt(Var1)'

## tan (double a)

Returns the tangent value (ratio of 2 sides) of the parameter (radians).

Parameter data type: double

Return value data type: double

##### Block

##### Text

'$Math.tan(EXPRESSION)'

(Example)

When Var1 is 1, output is 1.56.

##### Block

##### Text

'$Math.tan(Var1)'