Standard Library

Standard Library

Functions and function blocks that every IEC 61131-3 implementation must ship.

Functions

Pure functions — no instance, called directly.

  • Type-conversion<SRC>_TO_<DST>, TRUNC, BCD codecs.
  • ArithmeticABS, SQRT, LN/LOG/EXP, trig + inverse trig.
  • Comparison functionsGT, GE, EQ, LE, LT, NE (the function-form of the comparison operators; useful for variadic chained checks).
  • SelectionSEL, MUX, MIN, MAX, LIMIT.
  • StringLEN, LEFT/RIGHT/MID, CONCAT, INSERT, DELETE, REPLACE, FIND.
  • BitSHL, SHR, ROL, ROR. Includes the matiec emit-bug warning for SHL(BYTE#1, …).

Constants — not IEC core

IEC 61131-3 specifies the math functions but no constants. PI, E and friends are vendor extensions, and the vendors disagree on naming + scope. ForgeIEC offers an opt-in forgeiec_math library — but the portable approach is to declare what you need in a VAR_GLOBAL CONSTANT block in your project.

  • Mathematical constantsPI, E, SQRT2, GOLDEN_RATIO, … the cross-vendor table + how to declare them portably.
  • How to use constants and math — practical recipes (degrees↔radians, polar↔cartesian, dB-scaling, accumulator drift, domain validation before SQRT/LN).

Function blocks

Stateful — declare an instance, then call the instance.

  • Bistables: SR (set-dominant), RS (reset-dominant).
  • Edge detectors: R_TRIG (rising), F_TRIG (falling).
  • Counters: CTU, CTD, CTUD.
  • Timers: TON, TOF, TP.
  • Communication FBs (IEC 61131-5). (Not in matiec; project- specific extensions in ForgeIEC.)