# Math Function

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

First choose the Function below.

There is a variaty of functions:

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. | |

SINH | 1 | Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be ( | |

COS | 1 | Returns the trigonometric cosine of an angle. | |

COSH | 1 | Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be ( | |

TAN | 1 | Returns the trigonometric tangent of an angle. | |

TANH | 1 | Returns the hyperbolic tangent of a double value. | |

ACOS | 1 | Returns the arc cosine of a value; the returned angle is in the range | |

ASIN | 1 | Returns the arc sine of a value; the returned angle is in the range | |

ATAN | 1 | Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. | |

ATAN2 | 2 | Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). | |

EXP | 1 | Returns the value | |

EXPM1 | 1 | Returns | |

SQRT | 1 | Returns the correctly rounded positive square root of a double value. | |

CBRT | 1 | Returns the cube root of a double value. | |

GET_EXP | 1 | Returns the unbiased exponent used in the representation of a double. | |

HYPOT | 2 | Returns sqrt(x2 +y2) without intermediate overflow or underflow | |

LOG | 1 | Returns the natural logarithm (base e) of a double value. | |

LOG10 | 1 | Returns the base 10 logarithm of a double value. | |

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). | |

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 | |

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. | |

FLOOR_DIV | 2 | Returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient. | |

FLOOR_MOD | 2 | eturns the floor modulus of the long arguments | |

ABS | 1 | Returns the absolute value of a double value. | |

MIN | 2 | Returns the smaller of two double values. | |

MAX | 2 | Returns the greater of two double values | |

POW | 2 | Returns the value of the first argument raised to the power of the second argument. | |

SIGNUM | 1 | eturns 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. | |

RAD | 1 | Converts an angle measured in degrees to an approximately equivalent angle measured in radians. | |

DEG | 1 | Converts an angle measured in radians to an approximately equivalent angle measured in degrees. | |

Custom | 1-16 | Use this function to specify complex math expressions. For example, transform Fahrenheit to Celsius using (x - 32) / 1.8) |

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.

Last updated