EXPT

The IEC operator exponentiates one number with another and returns the base to the power of the exponent: power = baseexponent. Both base and exponent are input values (parameters). The power function is not defined if the base is 0 and the exponent is negative at the same time. However, the behavior in this case depends on the platform.

Syntax: EXPT(<base>,<exponent>)

Permitted data types for the input values: Basic numerical data types (SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT, REAL, LREAL, BYTE, WORD, DWORD, LWORD)

Permitted data types for the return value: Floating-point number types (REAL, LREAL).

If the result is stored in the REAL variable, a warning is generated for the conversion from LREAL to REAL. --> return type is always LREAL.

For example, a warning is generated for the following PLC code:

real1 := EXPT(real2,INT#2);

Samples:

a) power function with literals

Result: fVar is 49.

ST:

fVar := EXPT(7,2);

FBD:

EXPT 1:

b) power function with variables

Result: fPow is 128.

PROGRAM MAIN
VAR
    fPow      : LREAL;
    nBase     : INT := 2;
    nExponent : INT := 7;
END_VAR

fPow := EXPT(nBase, nExponent);