Skip to main content

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

FormulaSyntaxDescription
(( ... )Left parenthesis
)( ... )Right parenthesis
,(a1, ... )Comma — function parameter separator
;(a1; ... )Semicolon — function parameter separator
(space)(whitespace)Space

Arithmetic operators

FormulaSyntaxDescription
+a + bAddition
-a - bSubtraction
*a * bMultiplication
×a × bMultiplication (Unicode symbol)
a ∙ bMultiplication (Unicode symbol)
/a / bDivision
÷a ÷ bDivision (Unicode symbol)
^a^bExponentiation
!n!Factorial
#a # bRemainder (mod)
%n%Percent
√xSquare root (Unicode symbol)

Bitwise operators

FormulaSyntaxDescription
@~@~aBitwise unary inversion
@&a @& bBitwise AND
@^a @^ bBitwise XOR
@|a @| bBitwise OR
@<<a @<< bLeft shift with sign preservation
@>>a @>> bRight shift with sign preservation

Logical (boolean) operators

FormulaSyntaxDescription
&p & qLogical AND
&&p && qLogical AND
p ∧ qLogical AND (Unicode symbol)
|p | qLogical OR
||p || qLogical OR
p ∨ qLogical OR (Unicode symbol)
p ⊻ qExclusive OR (XOR) (Unicode symbol)
(+)p (+) qExclusive OR (XOR)
~~pNegation
¬¬pNegation (Unicode symbol)

Binary relations (comparisons)

FormulaSyntaxDescription
=a = bEqual
==a == bEqual
a ≠ bNot equal (Unicode symbol)
<>a <> bNot equal
~=a ~= bNot equal
!=a != bNot equal
<a < bLess than
>a > bGreater than
a ≤ bLess than or equal (Unicode symbol)
<=a <= bLess than or equal
a ≥ bGreater than or equal (Unicode symbol)
>=a >= bGreater than or equal

Unary functions

FormulaSyntaxDescription
sinsin(x)Trigonometric sine
coscos(x)Trigonometric cosine
tgtg(x)Trigonometric tangent
tantan(x)Trigonometric tangent
ctgctg(x)Trigonometric cotangent
cotcot(x)Trigonometric cotangent
lnln(x)Natural logarithm (base e)
log2log2(x)Binary logarithm (base 2)
lglg(x)Decimal logarithm (base 10)
log10log10(x)Decimal logarithm (base 10)
expexp(x)Exponential
sqrtsqrt(x)Square root
radrad(x)Degrees to radians
degdeg(x)Radians to degrees
absabs(x)Absolute value
sgnsgn(x)Sign of a number (Signum)
floorfloor(x)Round down (Floor)
ceilceil(x)Round up (Ceiling)
notnot(x)Negation

Binary functions

FormulaSyntaxDescription
loglog(a, b)Logarithm to base b
modmod(a, b)Remainder (mod)
roundround(x, n)Round "to nearest" to n digits
rootroot(rootorder, number)n-th root of a number

Conditional functions

FormulaSyntaxDescription
ifif(cond, expr-if-true, expr-if-false)If
iffiff(cond-1, expr-1; ... )"If" function (several "condition — expression" pairs)

Functions with an arbitrary number of arguments

FormulaSyntaxDescription
minmin(a1, ..., an)Minimum
maxmax(a1, ..., an)Maximum
meanmean(a1, ..., an)Mean value
addadd(a1, ..., an)Summation
multimulti(a1, ..., an)Multiplication
andand(a1, ..., an)Logical AND
oror(a1, ..., an)Logical OR
xorxor(a1, ..., an)Exclusive OR (XOR)
coalescecoalesce(a1, ..., an)Returns the first non-null argument

Constants

FormulaSyntaxDescription
ππThe number π (Unicode symbol)
pipiThe number π