Stand with Ukraine flag
Pricing Try it now
Community Edition
Getting Started Documentation Devices Library Guides Installation Architecture API FAQ

math function

Since TB Version 3.4.2

The rule node applies math function and saves the result into the message and/or database. See table of supported functions below:

Function Number of arguments Description Reference
ADD 2 x + y  
SUB 2 x - y  
MULT 2 x * y  
DIV 2 x / y  
SIN 1 Returns the trigonometric sine of an angle. Math.sin
SINH 1 Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Euler’s number. Math.sinh
COS 1 Returns the trigonometric cosine of an angle. Math.cos
COSH 1 Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be (ex + e-x)/2 where e is Euler’s number. Math.cosh
TAN 1 Returns the trigonometric tangent of an angle. Math.tan
TANH 1 Returns the hyperbolic tangent of a double value. Math.tanh
ACOS 1 Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. Math.acos
ASIN 1 Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. Math.asin
ATAN 1 Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. Math.atan
ATAN2 2 Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). Math.atan2
EXP 1 Returns the value ex, where e is the base of the natural logarithms. Math.exp
EXPM1 1 Returns ex-1. Note that for values of x near 0, the exact sum of expm1(x) + 1 is much closer to the true result of ex than exp(x). Math.expm1
SQRT 1 Returns the correctly rounded positive square root of a double value. Math.sqrt
CBRT 1 Returns the cube root of a double value. Math.cbrt
GET_EXP 1 Returns the unbiased exponent used in the representation of a double. Math.getExponent
HYPOT 2 Returns sqrt(x2 +y2) without intermediate overflow or underflow. Math.getExponent
LOG 1 Returns the natural logarithm (base e) of a double value. Math.log
LOG10 1 Returns the base 10 logarithm of a double value. Math.log10
LOG1P 1 Returns the natural logarithm of the sum of the argument and 1. Note that for small values x, the result of log1p(x) is much closer to the true result of ln(1 + x) than the floating-point evaluation of log(1.0+x). Math.log1p
CEIL 1 Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer. Math.ceil
FLOOR 1 Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. Math.floor
FLOOR_DIV 2 Returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient. Math.floorDiv
FLOOR_MOD 2 Returns the floor modulus of the long arguments. Math.floorMod
ABS 1 Returns the absolute value of a double value. Math.abs
MIN 2 Returns the smaller of two double values. Math.min
MAX 2 Returns the greater of two double values. Math.max
POW 2 Returns the value of the first argument raised to the power of the second argument. Math.pow
SIGNUM 1 Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero. Math.signum
RAD 1 Converts an angle measured in degrees to an approximately equivalent angle measured in radians. Math.toRadians
DEG 1 Converts an angle measured in radians to an approximately equivalent angle measured in degrees. Math.toDegrees
CUSTOM 1-16 Use this function to specify complex math expressions. For example, transform Fahrenheit to Celsius using (x - 32) / 1.8) exp4j

You may use 5 types of arguments:

  • Constant;
  • Value from the message body;
  • Value from the message meta data;
  • Value of the attribute that belongs to the message originator (device, asset, etc). Value should be of Numeric type or string that is convertible to float;
  • Value of the latest time-series that belongs to the message originator (device, asset, etc). Value should be of Numeric type or string that is convertible to float;

Primary use case for this rule node is to take one or more values from the database and modify them based on data from the message. For example, you may increase totalWaterConsumption based on the deltaWaterConsumption reported by device.

Alternative use case is the replacement of simple JS script nodes with more light-weight and performant implementation. For example, you may transform Fahrenheit to Celsius (C = (F - 32) / 1.8) using CUSTOM operation and expression: (x - 32) / 1.8).

The execution is synchronized in scope of message originator (e.g. device) and server node. If you have rule nodes in different rule chains, they will process messages from the same originator synchronously in the scope of the server node.

The result of the function may be added to the message body or metadata. You may also save the result to the database as an attribute or time-series.