StateTick Docs Home →
ST Logic Blocks

Arithmetic

Compute numeric values with the four arithmetic operators. Keep expressions simple — ST evaluates + - * / and nothing more exotic.

The four operators

+ add, - subtract, * multiply, / divide:

Global.Total  := Global.A + Global.B;
Global.Scaled := Param.Raw * Param.Gain;
Global.Avg    := Global.Sum / Param.Count;

Integers vs doubles

Dividing two Int values truncates toward zero — 7 / 2 is 3, not 3.5. For a fractional result, convert to Double first with INT_TO_REAL:

(* Percentage complete as a Double *)
Global.Pct := (INT_TO_REAL(Global.Done) / INT_TO_REAL(Global.Total)) * 100.0;

Precedence & parentheses

* and / bind tighter than + and -. Use parentheses when you want a different order or just to be explicit:

Global.X := Param.A + Param.B * 2;      (* B*2 first, then + A *)
Global.Y := (Param.A + Param.B) * 2;    (* sum first, then * 2 *)

That's the whole set. The IEC keywords MOD, DIV and XOR are reserved but not evaluated — don't use them. There are no ABS/MIN/MAX/SQRT helpers either. The only maths functions are the type conversions (INT_TO_REAL, REAL_TO_INT).