EXPT block
Short summary
Name |
EXPT |
→POU type |
|
Category |
|
Conform to →IEC-standard |
more possible than defined in IEC-standard;
|
Graphical interface |
|
Available since |
|
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).
Observe:
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). See "Examples for invalid Connections".
See "IEC-blocks for the application" for information what the consequences of an invalid connection might be.
You might want to use the IS_VALID block in your application to check the validity of ANY_REAL values.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 |
Description |
|
Inputs: |
IN1 |
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
1st value |
IN2 |
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
2nd value |
|
Return value: |
– |
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
|
Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.
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 connectionsFUNCTION_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 connectionsFUNCTION_BLOCK ExampleExptInvalid2
VAR
resultRealInvalid : REAL;
END_VAR
resultRealInvalid:= EXPT(IN1 := REAL#-25.0, IN2 := REAL#0.5); (* 'resultRealInvalid' evaluates to 'NaN' in the 'Values of Variables* view. *)
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 "