Skip to content

4.16 Arithmetic and Conditional Expressions

This section explains the expressions and conditional expressions that can be used in SpeeDBee Synapse.

4.16.1 Overview of expressions and conditional expressions#

Functions that can use expressions and conditional expressions are shown in SpeeDBee Synapse.

Item Expression Conditional expression Description
Compute Collector - This registers any computation results as Collector data.
Event
Data
- When the conditional expression is true, it is registered as data that match the condition.
Event
Trigger
- When the conditional expression is true, its event section information is output.
OUT Port
Conversion
- This registers any computation results as Collector data.
OUT Port
Conditions
- When a conditional expression is true, applicable data are registered.

4.16.2 Expression and conditional expression (common)#

This section describes expressions, conditional expressions, and formulas that can be used in both.

Item
Example ($VALUE + 10) * ABS(5)
Available comparison operations =,<>,!=,<,>,<=,>=
Available arithmetic operations (),+,-,*,/,%
Available logical operations AND,OR,NOT
Control statement IF
Available variables Description
$VALUE Value received from collector or calculation result by conversion formula
$PVALUE The value registered in the DB last time
$GVAR0-63 Global variable
$PVAR0-63 Persistence global variable
Note: Please refer to here for global variables.
Available constants Description
M_E Napier number, base of natural logarithm (e)
M_LOG2E log_e(e)
M_LOG10E log_10(e)
M_LN2 log_e(2)
M_LN10 log_10(e)
M_PI Pi
M_PI_2 Pi/2
M_PI_4 Pi/4
M_1_PI 1/Pi
M_2_SQRTPI 2/Pi
M_SQRT2 sqrt(2)
M_SQRT1_2 1/sqrt(2)
Available functions Description
ABS Absolute value (integer)
ACOS Trigonometric function: arc cosine
ASIN Trigonometric function: arc sine
ATAN Trigonometric function: arc tangent
CEIL Round up after the decimal point
COS Trigonometric function: cosine
COSH Hyperbolic cosine
EXP Exponential function with base Napier's number e
FABS Absolute value (float)
FLOOR Round down after the decimal point
FMOD Surplus
LOG Natural logarithms
LOG10 Logarithm with base 10
POW Power
ROUND Round to after the decimal point
SIN Trigonometric function: sine
SINH Hyperbolic sine
SQRT Square roots
TAN Trigonometric function: tangent
TANH Hyperbolic tangent

4.16.3 Expression#

This section describes expressions. An expression is a formula used to compute any given operation result. This is used when an operation needs to be performed on a value received from the collector.

Item
Example ($VALUE + 10) * ABS(5)
About assign of global variable (Reference)
GVAR1 := (expression)
  • The "$" is not necessary at the beginning of a global variable to be assigned.
  • When an assignment such as "GVAR1 := $VALUE * 2" is specified, the returned calculation result is the value of $VALUE multiplied by 2.
Example
GVAR1 := ($VALUE * 3)
(If $VALUE is 2.)
① 2 * 3 = 6 will be assigned to GVAR1.
② The operation result is the same as the value assigned to GVAR1 (6).
Assignment using the IF statement
IF (condition expression, value if true, value if false)
GVAR1 := IF($VALUE = 1,$GVAR1 + 1, $GVAR1)
In the above case, if $VALUE is 1 and it is true, the result of $GVAR1+1 is returned.
If false, $GVAR1 is assigned with the original value.
A caution is that if an assignment is made in "value if true" and "value if false", it is evaluated each time, regardless of whether the condition is true or false.
IF($VALUE=1,GVAR1 := $GVAR1 + 1, $GVAR1)
If specified this way, the "value if true" is evaluated as a formula and assigned every time, regardless of whether the condition is true or false. This may result in receiving an unintended value. Therefore, the assignment must be specified using a statement other than the IF statement.

4.16.4 Conditional expression#

This section describes conditional expressions. A conditional expression is an expression used to determine the truth value of a given condition. When a truth value is obtained, it can be used to control subsequent outputs.

Item
Example ($VALUE + 10) * ABS(5) < 100
About assign of global variable (Reference)
1 < (PVAR5 := (expression))
  • The "$" is not necessary at the beginning of a global variable to be assigned.
  • As in "PVAR5 := ($VALUE * 2)", it is not allowed to only specify an assignment. It must be specified as a conditional expression.
Example
GVAR1 := ($VALUE * 3)
(If $VALUE is 2.)
① 2 * 3 = 6 will be assigned to GVAR1.
② The operation result is the same as the value assigned to GVAR1 (6).