Apis Calculate

This module calculates an expression based on external inputs. An expression is given by mathematical symbols and external items as parameter to an expression. An external item is named in an expression by using the keyword ex1 for the first item in the connection list, ex2 as the second item in the connection list etc.

Provider: Prediktor

Properties

Commands And Events

The Calculate module has the following item types:

Variable item User defined item, which can be written and read.

Aggregated item An item which keeps the result value based on the item "Expression" property and external item(s).

More information

Quick Start Guide

Type of expressions

There are three types of expression which can be used:

  • Logical. Example: ex1&ex2

  • Condition based expressions. Example: (ex1&& ex2) || ((ex1<ex3) && (ex3>ex2))

  • Arithmetic expressions. Example: ex1+ex2 * sin(ex1-ex2)

Expressions for scalar inputs

Arithmetic equation operators

OperatorDescriptionExampleItem Type
+The sum of two valuesex1 + ex28 byte float (default) or custom scalar number
-The subtraction of one value from anotherex1 - ex28 byte float (default) or custom scalar number
*The multiplication of two valuesex1 * ex28 byte float (default) or custom scalar number
/The division of one value by anotherex1 / ex28 byte float (default) or custom scalar number

Comparison operators

OperatorDescriptionExampleItem Type
==Equalityex1 == ex2Boolean (default) or custom scalar number
<Less thanex1 < ex2Boolean (default) or custom scalar number
>Greater thanex1 > ex2Boolean (default) or custom scalar number
<=Less than or equalex1 <= ex2Boolean (default) or custom scalar number
>=Greater than or equalex1 >= ex2Boolean (default) or custom scalar number
<>Not equalex1 <> ex2Boolean (default) or custom scalar number
!=Not equalex1 != ex2Boolean (default) or custom scalar number

 Logical Operators

OperatorDescriptionExampleItem Type
&&ANDex1 && ex2Boolean (default) or custom scalar number
||ORex1 || ex2Boolean (default) or custom scalar number
!NOT!ex1Boolean (default) or custom scalar number

 Bitvise operations

OperatorDescriptionExampleItem Type
&Bitwise ANDex1 & ex2UInt64 (default) or custom scalar number
|Bitwise ORex1 | ex2UInt64 (default) or custom scalar number
^Bitwise XORex1 ^ ex2UInt64 (default) or custom scalar number
~Bitwise NOT~ex1UInt64 (default) or custom scalar number

 Functions

FunctionDescriptionExampleItem Type
absThe absolute valueabs(ex1)8 byte float (default) or custom scalar number
sinThe sine of a value, in radianssin(ex1)8 byte float (default) or custom scalar number
cosThe cosine of a value, in radianscos(ex1)8 byte float (default) or custom scalar number
tanThe tangent of a value, in radianstan(ex1)8 byte float (default) or custom scalar number
sqrtThe square root of a valuesqrt(ex1)8 byte float (default) or custom scalar number
powThe first value raised to the power of the second valuepow(ex1 , ex2)8 byte float (default) or custom scalar number
maxThe largest of two valuesmax(ex1 , ex2)16 byte fixed point (default) or custom scalar number
minThe smallest of two valuesmin(ex1, ex2)16 byte fixed point (default) or custom scalar number
negInvert signneg(ex1)8 byte float (default) or custom scalar number
floorRounds the value to nearest integer towards minus infinityfloor(ex1)16 byte fixed point (default) or custom scalar number
arcsinReturns the angle, θ, measured in radians, such that -π/2 ≤θ≤π/2 .The argument is a number must be greater than or equal to -1, but less than or equal to 1 Remarks:A positive return value represents a counterclockwise angle from the x-axis; a negative return value represents a clockwise angle.Multiply the return value by 180/Math.PI to convert from radians to degreesarcsin(ex1)8 byte float (default) or custom scalar number
arccosReturns the angle, θ, measured in radians, such that 0 ≤θ≤π.The argument is a number must be greater than or equal to -1, but less than or equal to 1 Remarks:Multiply the return value by 180/Math.PI to convert from radians to degrees.arccos(ex1)8 byte float (default) or custom scalar number
arctanReturns the angle, θ, measured in radians, such that -π/2 ≤θ≤π/2.-or-NaN if d equals NaN, -π/2 rounded to double precision (-1.5707963267949) if d equals NegativeInfinity, or π/2 rounded to double precision (1.5707963267949) if d equals PositiveInfinity. Remarks:A positive return value represents a counterclockwise angle from the x-axis; a negative return value represents a clockwise angle.Multiply the return value by 180/Math.PI to convert from radians to degreesarctan(ex1)8 byte float (default) or custom scalar number
sinhThe hyperbolic sine of value. If value is equal to NegativeInfinity. The parameter is an angle, measured in radians. Remarks:The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.sinh(ex1)8 byte float (default) or custom scalar number
coshThe hyperbolic cosine of value. If value is equal to NegativeInfinity or PositiveInfinity, PositiveInfinity is returned. If value is equal to NaN, NaN is returned. The parameter is an angle, measured in radians.Remarks:The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.cosh(ex1)8 byte float (default) or custom scalar number
tanhThe hyperbolic tangent of value. If value is equal to NegativeInfinity, this method returns -1. If value is equal to PositiveInfinity, this method returns 1. If value is equal to NaN, this method returns NaN. The parameter is an angle, measured in radians. Remarks:The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.tanh(ex1)8 byte float (default) or custom scalar number
asinhRepresents the inverse of the hyperbolic sine functionasinh(ex1)8 byte float (default) or custom scalar number
acoshRepresents the inverse of the hyperbolic cosine function.acosh(ex1)8 byte float (default) or custom scalar number
atanhRepresents the inverse of the hyperbolic tangent function.atanh(ex1)8 byte float (default) or custom scalar number

Expressions for vector and scalar inputs

Where the result has a boolean outcome, the value of -1 is a logical true, and 0 is a logical false.

Arithmetic equation operators

Vectors must have the same lengths.

OperatorDescriptionExampleItem Type
+The sum of two vectors, element by elementex1 + ex2Array of 8 byte float
-The subtraction of one vector from another, element by elementex1 - ex2Array of 8 byte float
*The multiplication of two vectors, element by elementex1 * ex2Array of 8 byte float
/The division of two vectors, element by elementex1 / ex2Array of 8 byte float

Comparison operators

When ex1 is a scalar and ex2 is a vector, the elements of the vector is compared with the scalar. The scalar must be the first element in the expression.

When ex1 and ex2 are both vectors, the comparison is done element by element.

Comparison operators can also be used in conjunction with the function Any.

Vectors must have the same lengths.

OperatorDescriptionExampleItem Type
==Equality.ex1 == ex2Array of 8 byte float
<Less thanex1 < ex2Array of 8 byte float
>Greater thanex1 > ex2Array of 8 byte float
<=Less than or equalex1 <= ex2Array of 8 byte float
>=Greater than or equalex1 >= ex2Array of 8 byte float
<>Not equalex1 <> ex2Array of 8 byte float
!=Not equalex1 != ex2Array of 8 byte float

Functions

FunctionDescriptionExampleItem Type
maxThe largest of the vector elementsmax(ex1)8 byte float (default) or custom scalar number
minThe smallest of the vector elementsmin(ex1)8 byte float (default) or custom scalar number
avgThe average value of the vector elementsavg(ex1)8 byte float (default) or custom scalar number
appendCombine two or more vectors into one larger vectorappend(ex1, ex2)Array of 8 byte float
splitGet a sub-vector of the external vector. The range is either hardkoded integers or scalar external items. The first argument is the source vector, the second argument is the start index and the third argument is the end index.split(ex1, ex2, ex3) and split(ex1, 2, 4)Array of 8 byte float
reverseReverse the order of the elements of a vectorreverse(ex1)Array of 8 byte float
interp1(table lookup)Lookup a value or values from a x-y table, where y is a function of x. First argument is the lookup target, second argument is the x-vector and the third argument is the y-vector. The lookup argument can be scalar or vector. If the lookup argument is a scalar, the result item will be a scalar. If the lookup argument is a vector, the resulting item is a vector of same size containg the y values for the argument elements. Interpolats when lookup argument is between x_min og x_max. If lookup argument is less than x_min, the value of y at x_min is returned. If lookup argument is larger than x_max, the value of y at x_max is returned.avg(ex1)Scalar target argument:8 byte float (default) or custom scalar number.Vector target argument: Array of 8 byte float
anyThe expressions of the Comparison Operators table can be placed inside an any function. The comparisons are done element by element, and any will return true if any of the individual comparisons are true.any(ex1 > ex2)boolean (default) or custom scalar number