Math
Rounding and Truncation
ABS
The ABS function returns the absolute value of a number.
VAR
result: REAL;
END_VAR
result := ABS(-5.3); // result is 5.3
CEIL
The CEIL function returns the smallest integer greater than or equal to a number.
VAR
result: REAL;
END_VAR
result := CEIL(5.3); // result is 6.0
FLOOR
The FLOOR function returns the largest integer less than or equal to a number.
VAR
result: REAL;
END_VAR
result := FLOOR(5.7); // result is 5.0
TRUNC
The TRUNC function returns the integer part of a number, effectively truncating the decimal part.
VAR
result: REAL;
END_VAR
result := TRUNC(5.7); // result is 5.0
Trigonometry
SIN
The SIN function returns the sine of an angle (in radians).
VAR
result: REAL;
END_VAR
result := SIN(3.14 / 2); // result is approximately 1.0
COS
The COS function returns the cosine of an angle (in radians).
VAR
result: REAL;
END_VAR
result := COS(3.14); // result is approximately -1.0
TAN
The TAN function returns the tangent of an angle (in radians).
VAR
result: REAL;
END_VAR
result := TAN(3.14 / 4); // result is approximately 1.0
ACOS
The ACOS function returns the arc cosine of a number.
VAR
result: REAL;
END_VAR
result := ACOS(1.0); // result is 0.0 (in radians)
ASIN
The ASIN function returns the arc sine of a number.
VAR
result: REAL;
END_VAR
result := ASIN(1.0); // result is 1.57 (in radians)
ATAN
The ATAN function returns the arc tangent of a number.
VAR
result: REAL;
END_VAR
result := ATAN(1.0); // result is 0.785 (in radians)
Exponential and Logarithmic
EXPT
The EXPT function returns the value of a number raised to the power of another number.
VAR
result: REAL;
END_VAR
result := EXPT(2.0, 3.0); // result is 8.0
EXP
The EXP function returns the value of e raised to the power of a number.
VAR
result: REAL;
END_VAR
result := EXP(1.0); // result is approximately 2.718
LN
The LN function returns the natural logarithm of a number.
VAR
result: REAL;
END_VAR
result := LN(2.718); // result is approximately 1.0
LOG
The LOG function returns the base-10 logarithm of a number.
VAR
result: REAL;
END_VAR
result := LOG(100.0); // result is 2.0
SQRT
The SQRT function returns the square root of a number.
VAR
result: REAL;
END_VAR
result := SQRT(9.0); // result is 3.0