Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Typed functions

An overloaded standard function can be called typed: its name, _, and a type, ADD_INT (Ed.3 6.6.2.4, Table 21). The typed function “is performed using the type as data type for its inputs and outputs”: each input is made that type first, by an implicit conversion, which only widens (Conversions), and the result is that type. So ADD_DINT(i, j) of two INTs adds in DINT, where i + j adds in INT; and NOT_WORD(b) of a BYTE widens it before it inverts. An input the type does not take implicitly is E0013: ADD_INT(d, i) of a DINT.

ExpressionTypeResultFlagNote
ADD_DINT(INT#30000, INT#30000)DINT60000—added as DINTs
ADD_INT(SINT#100, SINT#100, SINT#100)INT300—
MUL_INT(INT#300, INT#300)INT24464flag OVERFLOW90000 wrapped
SUB_LINT(UDINT#0, UDINT#1)LINT-1—
DIV_REAL(INT#7, INT#2)REAL3.5—
MOD_DINT(DINT#7, INT#3)DINT1—
ABS_LINT(SINT#-128)LINT128—
NOT_WORD(BYTE#16#0F)WORD16#FFF0—widened, then inverted
SHL_WORD(BYTE#16#81, 1)WORD16#0102—SHL(BYTE#16#81, 1) is 16#02
AND_DWORD(BYTE#16#FF, WORD#16#0F0F)DWORD16#0000000F—
MAX_LREAL(REAL#1.5, INT#2)LREAL2.0—
LIMIT_DINT(INT#0, DINT#-5, INT#10)DINT0—
SEL_LREAL(TRUE, INT#1, REAL#2.5)LREAL2.5—
MUX_UINT_DINT(UINT#1, INT#-5, DINT#7)DINT7—K a UINT, the inputs DINT
GT_DINT(INT#-1, DINT#0)BOOLFALSE—
EQ_LREAL(REAL#1.5, LREAL#1.5)BOOLTRUE—
SQRT_LREAL(REAL#2.25)LREAL1.5—
EXPT_REAL(REAL#2.0, 3)REAL8.0—
MOVE_LINT(SINT#-7)LINT-7—
CONCAT_STRING('ab', 'cd')STRING'abcd'—
LEFT_STRING('abc', 2)STRING'ab'—
FIND_STRING('abcd', 'cd')INT3—
MAX_CHAR(CHAR#'a', 'b')CHAR'b'—'b' a CHAR here

ADD_TIME, SUB_TIME, ADD_LTIME and SUB_LTIME are Table 30’s functions of durations, + and - of TIME or LTIME; MUL_TIME and DIV_TIME are Table 30’s too, a duration by a number (TIME and LTIME). CONCAT_DATE and the other Table 36 names are those functions, not typed forms of CONCAT.

ExpressionTypeResultFlagNote
ADD_TIME(T#1s, T#500ms)TIMET#1s500ms—
SUB_LTIME(LTIME#1s, T#1ms)LTIMELTIME#999ms—the TIME widened

Which functions are typed

Table 21 asks the implementer for “an additional table showing which functions are overloaded and which are typed”. In iecf, every overloaded standard function whose inputs share one type has a typed form, for each type of its inputs’ class:

FunctionTyped for
ABSthe integer and real types
SQRT, LN, LOG, EXP, SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2, EXPTREAL, LREAL
ADD, SUB, MUL, DIVthe integer and real types, TIME, LTIME
MODthe integer types
SHL, SHR, ROL, ROR, AND, OR, XOR, NOTthe bit strings and BOOL
MOVE, SEL, MAX, MIN, LIMIT, MUX, GT, GE, EQ, LE, LT, NEevery elementary type
LEFT, RIGHT, MID, INSERT, DELETE, REPLACE, FINDSTRING, WSTRING
CONCATSTRING, WSTRING, CHAR, WCHAR

MUX_K_T names K’s type and the inputs’ (Table 32, footnote c): MUX_UINT_REAL. A function whose inputs are of no one type - LEN, the conversions, the date and time functions - has none; a conversion is typed by its own name already (INT_TO_REAL, REAL_TRUNC_INT). Not compiled yet: a shift of BOOL.