Skip to main content Skip to footer

Math Documentation

Version: 1.0.0

Retrieved: 2025-10-09 15:16:01


Math

Allows you to do math operations written as a template, has support for basic functions as well as using message properties in the template.

Settings

Accessing properties in the math expressions from incoming messages is done by writing the property within {}.

Expression

Name Requirements Purpose Default
Expressions   Contains the Expressions.  

Expression

Name Requirements Purpose Default
Target Property String with length 1-64 Property that will contain the result of the expression. ''
Expression String with length 1-8192 The math expression to execute. ''

Input

The input requirement is that all the properties that are used in Expressions exist on the message or has been created as a target for a previous expression in the list of expressions, otherwise no restrictions.

Output

Same message as input with appended property that is set in Target Property for each expression, which contains the result from the Expression specifications.

Supported Functions

Name Description Usage Result
Abs Returns the absolute value of a specified number. Abs(-1) 1
Acos Returns the angle whose cosine is the specified number. Acos(1) 0
Asin Returns the angle whose sine is the specified number. Asin(0) 0
Atan Returns the angle whose tangent is the specified number. Atan(0) 0
Ceiling Returns the smallest integer greater than or equal to the specified number. Ceiling(1.5) 2
Cos Returns the cosine of the specified angle. Cos(0) 1
Exp Returns e raised to the specified power. Exp(0) 1
Floor Returns the largest integer less than or equal to the specified number. Floor(1.5) 1
IEEERemainder Returns the remainder resulting from the division of a specified number by another specified number. IEEERemainder(3, 2) -1
Log Returns the logarithm of a specified number. Log(1, 10) 0
Log10 Returns the base 10 logarithm of a specified number. Log10(1) 0
Max Returns the larger of two specified numbers. Max(1, 2) 2
Min Returns the smaller of two numbers. Min(1, 2) 1
Pow Returns a specified number raised to the specified power. Pow(3, 2) 9
Round Rounds a value to the nearest integer or specified number of decimal places. The mid number behavior can be changed by using EvaluateOption.RoundAwayFromZero during construction of the Expression object. Round(3.222, 2) 3.22
Sign Returns a value indicating the sign of a number. Sign(-10) -1
Sin Returns the sine of the specified angle. Sin(0) 0
Sqrt Returns the square root of a specified number. Sqrt(4) 2
Tan Returns the tangent of the specified angle. Tan(0) 0
Truncate Calculates the integral part of a number. Truncate(1.7) 1

Additional Functions

Name Description Usage Result
if Returns a value based on a condition. if(3 % 2 = 1, 'value is true', 'value is false') 'value is true'
The values to return can be strings, formulas, conditions or another if statement.

Examples

Example 1 - Basic expression

# Settings:
Expressions = [
    {
        Target Property = "result",
        Expression = "(10+11)/3"
    }
]

# Incoming message:
Does not matter, not using the input
# Outgoing message:
{
    "result": 7
}

Example 2 - Using data on incoming message

Calculating Newton meter from kw and rpm

# Settings:
Expressions = [
    {
        Target Property = "engine.nm",
        Expression = "(9550*{engine.kw})/{engine.rpm}"
    }
]

# Incoming message:
{
    engine:
    {
        "rpm": 3100,
        "kw": 198
    }
}
# Outgoing message:
{
    "engine":
    {
        "rpm": 3100,
        "kw": 198,
        "nm": 609.97
    }
}

Example 3 - Chaining several expressions

Showing that you can use the output from a previous expression in the next one(s). We name them all result here, but you can name them anything, but adding distinct targets will also affect the output since they all will be added to the flow message.

# Settings:
Expressions = [
    {
        Target Property = "result",
        Expression = "6*6"
    },
    {
        Target Property = "result",
        Expression = "{result}*2"
    },
    {
        Target Property = "result",
        Expression = "{result}+10"
    }
]

# Incoming message:
Does not matter, not using the input

# Outgoing message:
{
    "result": 82
}

Example 4 - Using expressions on incoming message

Calculating fahrenheit from celsius using expressions from the incoming message in combination with a expression in the settings.

# Settings:
Expressions = [
    {
        Target Property = "data.fahrenheit",
        Expression = "{expression}+32"
    }
]

# Incoming message:
{
	"expression": "{data.celsius}*9/5",
	"data": {
		"celsius": 25.5
	}
}

# Outgoing message:
{
    "expression": "{data.celsius}*9/5",
    "data": {
        "celsius": 25.5,
        "fahrenheit": 77.9
    }
}

Operators

Expressions can be combined using operators. Each operator has a precedence priority. Here is the list of those expression's priority.

  1. primary
  2. unary
  3. multiplicative
  4. additive
  5. relational
  6. logical

Logical

These operators can do some logical comparison between other expressions: or, || and, &&

  true or false and true

The and operator has higher priority than the or operator, thus in the example above, false and true is evaluated first.

Relational

=, ==, !=, <> <, <=, >, >=

  1 < 2

Additive

+, -

  1 + 2 - 3

Multiplicative

*, /, %

 1 * 2 % 3

Bitwise

& (bitwise and), | (bitwise or), ^(bitwise xor), << (left shift), >>(right shift)

  2 >> 3

Unary

!, not, -, ~ (bitwise not)

  not true

Primary

(, ) values

  2 * ( 3 + 2 )