Named constants
Named constants
Special input values can be used for inputs on function blocks of the type MC_LREAL (see the chapter MC_LREAL/Special input values). The MC3 uses only the standard data type LREAL instead of MC_LREAL and supports the use of so-called named constants.
Named constants are silent NaN values according to IEEE 754, used to indicate uninitialized or invalid data. The mantissa is encoded in a Beckhoff-specific bit pattern. The advantage is improved readability, for example, when viewed online. For example, the previous default value of 0 can be interpreted as a placeholder for the default dynamics or as the actual value 0. In this case, misinterpretations or incorrect mathematical operations are possible.
The following points rank among the main properties of NaN values:
- All arithmetic operations that use NaN as input data return NaN as the result.
- All relational operators =, !=, > < >= <= always return the value False if at least one of the operands is NaN.
- The Standard C functions
isnan()and_isnan(), as well as the PLC functions LrealIsNaN() and RealIsNaN() (Tc2_Utilities library), return True if the argument has the value NaN. - The expression
isnan(a)is equivalent to the expression!(a == a)orNOT(a = a).
The fact that NaN values propagate when used in further calculations has the advantage that invalid values cannot be overlooked.
| |
Software malfunctions NaN values can lead to potentially dangerous malfunctions of the software concerned!
|
For further information, see the chapter on NaN values.
The syntax for use in the PLC is STRING_TO_LREAL('[Wert]') or the shorthand form TO_LREAL('[Wert]'). The following constants can be used for the MC3:
Value | Meaning | Example |
|---|---|---|
#Invalid | Invalid value | Default input value for |
#Default | Can be used, for example, to use the axis's default dynamics as input for function blocks. |
|
#Ignore | Can be used to disable inputs or boundary conditions. | Disabling the software limit switches on one side. Define the position derivatives as input or boundary conditions for the MotionFunctionPoints (camming) to be ignored. |
#Maximum | Can be used, for example, to use the maximum dynamics of the axis as input for function blocks. |
|
#MaximumNegative | Can be used, for example, to use the inverted maximum dynamics of the axis as input for function blocks. |
|
#DefaultNegative | Can be used, for example, to use the inverted default dynamics of the axis as input for function blocks. |
|
The syntax and usage of named constants have been optimized in TwinCAT 3.1 Build 4026.25 and are described below.
![]() | Available from TwinCAT 3.1 Build 4026.25 |
Special values, such as NaN (Not a Number), are now provided as type-safe constants. The LREAL_CONST namespace provides access to the following variables:
Constant | Meaning |
|---|---|
DEFAULT | Application-specific default value (positive) |
IGNORE | Marker value “do not evaluate” |
INVALID | Marker value for invalid size |
MAXIMUM | Largest finite positive value |
DEFAULT_NEGATIVE | Application-specific default value (negative) |
MAXIMUM_NEGATIVE | Largest finite negative value |
NAN | Not a Number |
INFINITY | Positive infinity |
INFINITY_NEGATIVE | Negative infinity |
Example: Using
VAR
fNumerator : LREAL;
fDenominator : LREAL;
fResult : LREAL
END_VAR
IF fDenominator = 0 THEN
fDenominator := LREAL_CONST.NAN;// invalid: division by zero
END_IF
fResult := fNumerator / fDenominator;
