# Standard functions

> The IEC 61131-3 standard functions the eaxPLC ST compiler accepts: arguments, result type and behaviour.

Product: eaxPLC · Type: Reference · Editions: Free
Source: https://eaxware.com/docs/eaxplc/reference/generated/iec/standard-functions/
Verified against commit 54fdce6.

<!-- GENERATED by tools/docgen (node tools/docgen/docgen.mjs). Do not edit by hand: change the source and regenerate. -->

The standard functions the ST compiler accepts in expressions. Function blocks are documented separately.

## Numeric

| Function | Arguments | Returns | Description |
|---|---|---|---|
| `ABS` | IN: ANY_NUM | type of IN | Absolute value. |
| `TRUNC` | IN: ANY_NUM | DINT | Truncates toward zero. |
| `EXPT` | IN1: ANY_NUM, IN2: ANY_NUM | REAL (LREAL when the target is LREAL) | IN1 raised to the power IN2, computed in LREAL. |

## Math

| Function | Arguments | Returns | Description |
|---|---|---|---|
| `SQRT` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Square root. |
| `LN` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Natural logarithm. |
| `LOG` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Base-10 logarithm. |
| `EXP` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Natural exponential. |
| `SIN` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Sine (radians). |
| `COS` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Cosine (radians). |
| `TAN` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Tangent (radians). |
| `ASIN` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Arc sine (radians). |
| `ACOS` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Arc cosine (radians). |
| `ATAN` | IN: ANY_NUM | REAL (LREAL when the target is LREAL) | Arc tangent (radians). |

## Selection

| Function | Arguments | Returns | Description |
|---|---|---|---|
| `MIN` | IN1, IN2, ... (2 or more, ANY_NUM) | common type of the inputs | Smallest input. |
| `MAX` | IN1, IN2, ... (2 or more, ANY_NUM) | common type of the inputs | Largest input. |
| `LIMIT` | MN, IN, MX (ANY_NUM) | common type of the inputs | IN clamped to [MN, MX]: MIN(MAX(IN, MN), MX). |
| `SEL` | G: BOOL, IN0, IN1 | common type of IN0 and IN1 | IN0 when G is FALSE, IN1 when G is TRUE. |
| `MUX` | K: ANY_INT, IN0, IN1, ... (1 or more inputs) | common type of the inputs | The input selected by K (0 = IN0). |

## Bit strings

| Function | Arguments | Returns | Description |
|---|---|---|---|
| `SHL` | IN: ANY_BIT, N: ANY_INT | type of IN (DWORD for an untyped literal) | Shift left by N bits; bits above the width of IN are dropped. |
| `SHR` | IN: ANY_BIT, N: ANY_INT | type of IN (DWORD for an untyped literal) | Shift right by N bits (the unsigned bit pattern of IN). |
| `ROL` | IN: ANY_BIT, N: ANY_INT | type of IN (DWORD for an untyped literal) | Rotate left by N bits within the width of IN. |
| `ROR` | IN: ANY_BIT, N: ANY_INT | type of IN (DWORD for an untyped literal) | Rotate right by N bits within the width of IN. |
| `EXTRACT` | X: ANY_BIT, N: ANY_INT | BOOL | Bit N of X. |
| `PUTBIT` | X: ANY_BIT, N: ANY_INT, B: BOOL | type of X (DWORD for an untyped literal) | X with bit N set to B. |
| `PACK` | B0, B1, ..., B7 (8 BOOL) | BYTE | Packs eight BOOLs into a BYTE (B0 = bit 0). |

## Strings

| Function | Arguments | Returns | Description |
|---|---|---|---|
| `LEN` | IN: STRING | INT | Length of IN. |
| `LEFT` | IN: STRING, L: ANY_INT | STRING | The leftmost L characters of IN. |
| `RIGHT` | IN: STRING, L: ANY_INT | STRING | The rightmost L characters of IN. |
| `MID` | IN: STRING, L: ANY_INT, P: ANY_INT | STRING | L characters of IN from position P. |
| `CONCAT` | IN1, IN2, ... (2 or more STRING) | STRING | The inputs joined in order. |
| `FIND` | IN1: STRING, IN2: STRING | INT | Position of IN2 in IN1 (0 when absent). |
| `INSERT` | IN1: STRING, IN2: STRING, P: ANY_INT | STRING | IN2 inserted into IN1 after position P. |
| `DELETE` | IN: STRING, L: ANY_INT, P: ANY_INT | STRING | IN without the L characters from position P. |
| `REPLACE` | IN1: STRING, IN2: STRING, L: ANY_INT, P: ANY_INT | STRING | IN1 with L characters from position P replaced by IN2. |

## Conversions

| Function | Arguments | Returns | Description |
|---|---|---|---|
| `BCD_TO_INT` | IN: ANY_INT | INT | Binary-coded decimal to integer. |
| `BCD_TO_DINT` | IN: ANY_INT | DINT | Binary-coded decimal to integer. |
| `INT_TO_BCD` | IN: ANY_INT | WORD | Integer to binary-coded decimal. |
| `DINT_TO_BCD` | IN: ANY_INT | DWORD | Integer to binary-coded decimal. |
| `_TO_` | IN: &lt;FROM&gt; | &lt;TO&gt; | Type conversion between any two of the conversion types. Real to integer rounds half to even; narrowing wraps; BOOL to and from numbers is 0/1. |

In `_TO_`, each of FROM and TO is one of: `BOOL`, `BYTE`, `DINT`, `DWORD`, `INT`, `LINT`, `LREAL`, `LWORD`, `REAL`, `SINT`, `STRING`, `TIME`, `UDINT`, `UINT`, `ULINT`, `USINT`, `WORD`.
