Appendix 1. Binary, logical and mathematical expressions
The GALAKTIKA system supports calculated sensors — sensors whose value is computed by a
formula from the values of other sensors and raw device parameters. The formula is entered in
the Formula field on the sensor's Calibration tab (see
Admin panel → Monitored objects).
Formulas may use arithmetic, bitwise and logical operations, comparison operations, and a set
of mathematical functions and constants. The supported syntax is listed below.
Notation
The Syntax column uses the following argument conventions:
a, b, x, y — numeric arguments or nested expressions;
p, q — logical expressions;
n, k — integers;
a1, ..., an — an arbitrary number of arguments.
Many operators have both an ASCII form and an equivalent Unicode symbol — such variants are
marked "Unicode symbol" in the list.
Numbers and parser symbols
Numeric literals are supported in various formats: integers (1, -2), decimals
(0.2, -0.3), with a leading zero (001, -002.1), in scientific notation (1.2e-10,
2.3E10), without a leading zero (.2, -.212), fractions (1_2, 2_1_3, -14_3), and in
other number bases (b1.111 — binary, o.0127 — octal, h.af1 — hexadecimal).
| Formula | Syntax | Description |
|---|
( | ( ... ) | Left parenthesis |
) | ( ... ) | Right parenthesis |
, | (a1, ... ) | Comma — function parameter separator |
; | (a1; ... ) | Semicolon — function parameter separator |
| (space) | (whitespace) | Space |
Arithmetic operators
| Formula | Syntax | Description |
|---|
+ | a + b | Addition |
- | a - b | Subtraction |
* | a * b | Multiplication |
× | a × b | Multiplication (Unicode symbol) |
∙ | a ∙ b | Multiplication (Unicode symbol) |
/ | a / b | Division |
÷ | a ÷ b | Division (Unicode symbol) |
^ | a^b | Exponentiation |
! | n! | Factorial |
# | a # b | Remainder (mod) |
% | n% | Percent |
√ | √x | Square root (Unicode symbol) |
Bitwise operators
| Formula | Syntax | Description |
|---|
@~ | @~a | Bitwise unary inversion |
@& | a @& b | Bitwise AND |
@^ | a @^ b | Bitwise XOR |
@| | a @| b | Bitwise OR |
@<< | a @<< b | Left shift with sign preservation |
@>> | a @>> b | Right shift with sign preservation |
Logical (boolean) operators
| Formula | Syntax | Description |
|---|
& | p & q | Logical AND |
&& | p && q | Logical AND |
∧ | p ∧ q | Logical AND (Unicode symbol) |
| | p | q | Logical OR |
|| | p || q | Logical OR |
∨ | p ∨ q | Logical OR (Unicode symbol) |
⊻ | p ⊻ q | Exclusive OR (XOR) (Unicode symbol) |
(+) | p (+) q | Exclusive OR (XOR) |
~ | ~p | Negation |
¬ | ¬p | Negation (Unicode symbol) |
Binary relations (comparisons)
| Formula | Syntax | Description |
|---|
= | a = b | Equal |
== | a == b | Equal |
≠ | a ≠ b | Not equal (Unicode symbol) |
<> | a <> b | Not equal |
~= | a ~= b | Not equal |
!= | a != b | Not equal |
< | a < b | Less than |
> | a > b | Greater than |
≤ | a ≤ b | Less than or equal (Unicode symbol) |
<= | a <= b | Less than or equal |
≥ | a ≥ b | Greater than or equal (Unicode symbol) |
>= | a >= b | Greater than or equal |
Unary functions
| Formula | Syntax | Description |
|---|
sin | sin(x) | Trigonometric sine |
cos | cos(x) | Trigonometric cosine |
tg | tg(x) | Trigonometric tangent |
tan | tan(x) | Trigonometric tangent |
ctg | ctg(x) | Trigonometric cotangent |
cot | cot(x) | Trigonometric cotangent |
ln | ln(x) | Natural logarithm (base e) |
log2 | log2(x) | Binary logarithm (base 2) |
lg | lg(x) | Decimal logarithm (base 10) |
log10 | log10(x) | Decimal logarithm (base 10) |
exp | exp(x) | Exponential |
sqrt | sqrt(x) | Square root |
rad | rad(x) | Degrees to radians |
deg | deg(x) | Radians to degrees |
abs | abs(x) | Absolute value |
sgn | sgn(x) | Sign of a number (Signum) |
floor | floor(x) | Round down (Floor) |
ceil | ceil(x) | Round up (Ceiling) |
not | not(x) | Negation |
Binary functions
| Formula | Syntax | Description |
|---|
log | log(a, b) | Logarithm to base b |
mod | mod(a, b) | Remainder (mod) |
round | round(x, n) | Round "to nearest" to n digits |
root | root(rootorder, number) | n-th root of a number |
Conditional functions
| Formula | Syntax | Description |
|---|
if | if(cond, expr-if-true, expr-if-false) | If |
iff | iff(cond-1, expr-1; ... ) | "If" function (several "condition — expression" pairs) |
Functions with an arbitrary number of arguments
| Formula | Syntax | Description |
|---|
min | min(a1, ..., an) | Minimum |
max | max(a1, ..., an) | Maximum |
mean | mean(a1, ..., an) | Mean value |
add | add(a1, ..., an) | Summation |
multi | multi(a1, ..., an) | Multiplication |
and | and(a1, ..., an) | Logical AND |
or | or(a1, ..., an) | Logical OR |
xor | xor(a1, ..., an) | Exclusive OR (XOR) |
coalesce | coalesce(a1, ..., an) | Returns the first non-null argument |
Constants
| Formula | Syntax | Description |
|---|
π | π | The number π (Unicode symbol) |
pi | pi | The number π |