Function Block CALCULATE

The Function Block CALCULATE calculates a complex mathematical formula.

The complete formula is compiled directly, therefore the execution of this function block is very efficient.

Warning: Division by zero can lead to unwanted results.

Database

The database defines the calculation as a string. An optional = sign can be used to specify the output. The variables in the calculation are sorted and displayed. Note the possible operations below, which differ from mathematical formulas.

Note: If a number is defined with an exponent, it may not be recognized correctly. Therefore, use parentheses if necessary.

Incorrect formulas will not be compiled and return the error as a string.

Inputs

The inputs can be displayed arbitrarily. Depending on how many variables occur in the formula, these are automatically generated.

Outputs

The outputs return the calculated result or intermediate result. The name can be defined by an = sign in the formula. Use a ; (semicolon) in the formula to create multiple calculations. The last calculation is output at the first output.

Operations

Note that the first = sign is used for declaring the output.

Function Description
-a Negation. Countervalue of a.
a . b Concatenates the two values as a string.
a + b Addition. Sum of a and b.
a - b Subtraction. Difference of a and b.
a * b Multiplication. Product of a and b.
a / b Division. Quotient of a and b.
a % b or mod (a,b) Modulus. Remainder of a divided by b.
expt(a,b) Power. B-th power of a.
exrt(a,b) Arbitrary root b from the value a.
sqrt(a) Square root.
ln(a,b) Calculates the natural logarithm of a to base b.
log(a) Calculates the decimal logarithm.
abs(a) Absolute value of a.
neg(a) Negative value of a. Same as -a.
deg2rad(a) Conversion from degrees to radians.
rad2deg(a) Conversion from radians to degrees.
hex2dec(a) Conversion from hexadecimal to decimal.
dec2hex(a) Conversion from decimal to hexadecimal.
oct2dec(a) Conversion from octal to decimal.
dec2oct(a) Conversion from decimal to octal.
fmod(a,b) Remainder of a floating-point division
cos(a) Cosine.
acos(a) Arccosine.
sin(a) Sine.
asin(a) Arcsine.
tan(a) Tangent.
atan(a) Arctangent.
hypot(a,b) Calculates the hypotenuse of a right triangle.
ceil(a) Round up.
floor(a) Round down.
round(a,b) Rounds a floating-point value.
min(a,b[,..]) Returns the smallest value.
max(a,b[,..]) Returns the largest value.
a & b AND bit operation.
a | b OR bit operation.
a ^ b XOR bit operation.
~a NOT bit operation.
a << b Shift bits of a by b positions to the left.
a >> b Shift bits of a by b positions to the right.
!a NOT operation (boolean value)
a && b or a and b AND (boolean value)
a || b or a or b OR (boolean value)
++a Increases a by one, and then returns a.
a++ Returns a, and then increases a by one.
--a Decreases a by one, and then returns a.
a-- Returns a, and then decreases a by one.
== Equal (boolean value)
=== Exactly identical (boolean value)
is_null(a) or a === null Is equal to NULL.
a <> b or a != b A is not equal to b.
a < b Less than (boolean value)
a <= b Less than or equal to (boolean value)
a > b Greater than (boolean value)
a >=b Greater than or equal to (boolean value)
s?a:b or (s == 1)?a:b Selects between a and b. If s is true, a is returned.
; Separator for calculation in multiple steps.

Constants

All constants of Antcas Control can be used. Note the uppercase and lowercase letters.

Examples