EXPT block

Short summary

Name

EXPT

→POU type

→function

Category

IEC-block, Numeric, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg more possible than defined in IEC-standard;
(IEC demands ANY_REAL for the input IN1 and the return value.)

and

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/error.svg currently restricted
(IEC demands error handling, if the result of the block exceeds the range of values for the output data type. See " No check of invalid connections " for the behavior in logi.CAD 3. )

Graphical interface

images/download/thumbnails/414781988/EXPT-version-1-modificationdate-1535031959475-api-v2.png

Available since

  • version 1.0.0 (for logi.CAD 3) – initial variant

  • version 2.0.16 (for library Standard) – enhancement: internal error diagnostic, refactoring to guarantee the calculation of correct results for connected ANY_INT values

  • version 3.1.0 (for library Standard) – For inputs of data type REAL, the optimized float variant of the C-runtime is used. Compared to previous versions , it is possible that (marginal) other results are returned within the threshold range of the block.

Functionality

The mathematical function exponentation is called: The block returns the result of IN1IN2 (the value connected to IN1 is exponentiated by the value connected to IN2).

Behavior for calculation 0**0

The EXPT block returns the result 1 for the calculation 0**0 . In this case, the ENO output of EXPT is not reset to FALSE but TRUE is returned.

Observe as well:

  • For ANY_REAL values:

    No check of invalid connections

    For some blocks, invalid connections are not checked by logi.CAD 3. Therefore, enter code in your application to detect invalid connections (e.g. IF-statements in the ST-code). See "Examples for invalid Connections".

    See "IEC-blocks for the application" for information what the consequences of an invalid connection might be.


    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/lightbulb.svg You might want to use the IS_VALID block in your application to check the validity of ANY_REAL values.

    Restriction

    For the platform "vxWorks x86", the EXPT block does not return "Not-a-Number" (NaN) in case of an invalid connection of the EXPT block with ANY_REAL values. See also "EXPT block returns a wrong value under certain target system in case of an invalid connection".

  • For ANY_INT values (see under "Example for usage within ST-editor" ):

    • If the return value exceeds the upper limit of the data type, the block returns the upper limit of the data type. In this case, the output ENO is set to value FALSE.

    • If the return value is below the lower limit of the data type, the block returns the lower limit of the data type. In this case, the output ENO is set to value FALSE as well.

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN1

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT
(corresponds to →generic data type ANY_NUM)

1st value

IN2

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT
(corresponds to →generic data type ANY_NUM)

2nd value

Return value:

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT
(corresponds to →generic data type ANY_NUM)


Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Internal error diagnostic for block

The block checks the return value. The output ENO of the block is set to value FALSE (or an equivalent) in the following cases:

  • The return value exceeds the upper limit of the data type. (Moreover for this case, the blocks returns the upper limit of the data type.)

  • The return value is below the lower limit of the data type. (Moreover for this case, the blocks returns the lower limit of the data type.)

Example for usage within ST-editor

The calculated values are evaluated by using the Assert block .

FUNCTION_BLOCK ExampleExpt
VAR
resultReal : REAL;
resultSint : SINT;
END_VAR
 
resultReal := EXPT(IN1 := 3.0, IN2 := 4);
Assert(resultReal = 81.0);
 
resultSint := EXPT(IN1 := 2, IN2 := 3);
Assert(resultSint = 8);
END_FUNCTION_BLOCK

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.

Examples for invalid connections

Invalid connections might occur in the following cases during a calculation using EXPT.

  • due to →overflows or →underflows

    Examples for invalid connections
    FUNCTION_BLOCK ExampleExptInvalid1
    VAR
    resultSint1, resultSint2 : SINT;
    CheckENO1, CheckENO2 : BOOL;
    END_VAR
     
    resultSint1 := EXPT(IN1 := SINT#10, IN2 := SINT#3, ENO=>CheckENO1); (* The upper limit for SINT is '127'. '10**3' causes an overflow as '10**3' would evaluate to '1000'. *)
    Assert(resultSint1 = 127);
    Assert(CheckENO1 = FALSE);
     
    resultSint2 := EXPT(IN1 := SINT#-10, IN2 := SINT#3, ENO=>CheckENO2); (* The lower limit for SINT is '-128'. '-10**3' causes a negative overflow as '-10**3' would evaluate to '-1000'. *)
    Assert(resultSint2 = -128);
    Assert(CheckENO2 = FALSE);
     
    END_FUNCTION_BLOCK
  • if IN1 < 0 and IN2 is not an →integer

    Example for invalid connections
    FUNCTION_BLOCK ExampleExptInvalid2
    VAR
    resultRealInvalid : REAL;
    END_VAR
     
    resultRealInvalid:= EXPT(IN1 := REAL#-25.0, IN2 := REAL#0.5);
    (* For the built-in PLC, 'resultRealInvalid' evaluates to 'NaN' in the 'Values of Variables* view. *)
    (* But this is not the case for vxWorks x86. *)
    ASSERT(NOT IS_VALID(resultRealInvalid));
     
    END_FUNCTION_BLOCK

See also " EXPT block returns a wrong value under certain target system in case of an invalid connection ".