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
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
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
Operator | Description | Example | Item Type |
---|---|---|---|
+ | The sum of two values | ex1 + ex2 | 8 byte float (default) or custom scalar number |
- | The subtraction of one value from another | ex1 - ex2 | 8 byte float (default) or custom scalar number |
* | The multiplication of two values | ex1 * ex2 | 8 byte float (default) or custom scalar number |
/ | The division of one value by another | ex1 / ex2 | 8 byte float (default) or custom scalar number |
Comparison operators
Operator | Description | Example | Item Type |
---|---|---|---|
== | Equality | ex1 == ex2 | Boolean (default) or custom scalar number |
< | Less than | ex1 < ex2 | Boolean (default) or custom scalar number |
> | Greater than | ex1 > ex2 | Boolean (default) or custom scalar number |
<= | Less than or equal | ex1 <= ex2 | Boolean (default) or custom scalar number |
>= | Greater than or equal | ex1 >= ex2 | Boolean (default) or custom scalar number |
<> | Not equal | ex1 <> ex2 | Boolean (default) or custom scalar number |
!= | Not equal | ex1 != ex2 | Boolean (default) or custom scalar number |
Logical Operators
Operator | Description | Example | Item Type |
---|---|---|---|
&& | AND | ex1 && ex2 | Boolean (default) or custom scalar number |
|| | OR | ex1 || ex2 | Boolean (default) or custom scalar number |
! | NOT | !ex1 | Boolean (default) or custom scalar number |
Bitvise operations
Operator | Description | Example | Item Type |
---|---|---|---|
& | Bitwise AND | ex1 & ex2 | UInt64 (default) or custom scalar number |
| | Bitwise OR | ex1 | ex2 | UInt64 (default) or custom scalar number |
^ | Bitwise XOR | ex1 ^ ex2 | UInt64 (default) or custom scalar number |
~ | Bitwise NOT | ~ex1 | UInt64 (default) or custom scalar number |
Functions
Function | Description | Example | Item Type |
---|---|---|---|
abs | The absolute value | abs(ex1) | 8 byte float (default) or custom scalar number |
sin | The sine of a value, in radians | sin(ex1) | 8 byte float (default) or custom scalar number |
cos | The cosine of a value, in radians | cos(ex1) | 8 byte float (default) or custom scalar number |
tan | The tangent of a value, in radians | tan(ex1) | 8 byte float (default) or custom scalar number |
sqrt | The square root of a value | sqrt(ex1) | 8 byte float (default) or custom scalar number |
pow | The first value raised to the power of the second value | pow(ex1 , ex2) | 8 byte float (default) or custom scalar number |
max | The largest of two values | max(ex1 , ex2) | 16 byte fixed point (default) or custom scalar number |
min | The smallest of two values | min(ex1, ex2) | 16 byte fixed point (default) or custom scalar number |
neg | Invert sign | neg(ex1) | 8 byte float (default) or custom scalar number |
floor | Rounds the value to nearest integer towards minus infinity | floor(ex1) | 16 byte fixed point (default) or custom scalar number |
arcsin | Returns 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 degrees | arcsin(ex1) | 8 byte float (default) or custom scalar number |
arccos | Returns 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 |
arctan | Returns 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 degrees | arctan(ex1) | 8 byte float (default) or custom scalar number |
sinh | The 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 |
cosh | The 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 |
tanh | The 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 |
asinh | Represents the inverse of the hyperbolic sine function | asinh(ex1) | 8 byte float (default) or custom scalar number |
acosh | Represents the inverse of the hyperbolic cosine function. | acosh(ex1) | 8 byte float (default) or custom scalar number |
atanh | Represents 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.
Operator | Description | Example | Item Type |
---|---|---|---|
+ | The sum of two vectors, element by element | ex1 + ex2 | Array of 8 byte float |
- | The subtraction of one vector from another, element by element | ex1 - ex2 | Array of 8 byte float |
* | The multiplication of two vectors, element by element | ex1 * ex2 | Array of 8 byte float |
/ | The division of two vectors, element by element | ex1 / ex2 | Array 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.
Operator | Description | Example | Item Type |
---|---|---|---|
== | Equality. | ex1 == ex2 | Array of 8 byte float |
< | Less than | ex1 < ex2 | Array of 8 byte float |
> | Greater than | ex1 > ex2 | Array of 8 byte float |
<= | Less than or equal | ex1 <= ex2 | Array of 8 byte float |
>= | Greater than or equal | ex1 >= ex2 | Array of 8 byte float |
<> | Not equal | ex1 <> ex2 | Array of 8 byte float |
!= | Not equal | ex1 != ex2 | Array of 8 byte float |
Functions
Function | Description | Example | Item Type |
---|---|---|---|
max | The largest of the vector elements | max(ex1) | 8 byte float (default) or custom scalar number |
min | The smallest of the vector elements | min(ex1) | 8 byte float (default) or custom scalar number |
avg | The average value of the vector elements | avg(ex1) | 8 byte float (default) or custom scalar number |
append | Combine two or more vectors into one larger vector | append(ex1, ex2) | Array of 8 byte float |
split | Get 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 |
reverse | Reverse the order of the elements of a vector | reverse(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 |
any | The 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 |