Type
| Function |
Description
| The overloaded function TO_LREAL converts an input value of various data types into an output value of the data type LREAL (see description of the input for the supported data types). |
Parameters
| Input
IN
Data type: | The function is available for the following input data types:
- BOOL, LWORD
- Integers: SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT
- Floating point numbers: REAL
- STRING
|
Output
OUT
|
Conversion rules
| ANY_BIT conversion
The data type conversion of the source data type LWORD is done as binary transfer (bitwise copy from the source data type to the LREAL data type). For the BOOL to LREAL conversion, the input value FALSE results in 0.0 and the input value TRUE in 1.0.
ANY_INT conversion
The numeric value is converted into the LREAL format according to the IEC 60559 standard. Here, the basic double width floating format is defined. Mantissa and exponent are set automatically.
REAL conversion
REAL values can also be converted implicitly to LREAL values.
LWORD conversion
The LWORD_TO_LREAL conversion complies with the latest standardization by the IEC 61131-3, 3rd edition. The floating point value is stored according to the IEEE 754 standard.
STRING conversion
- The string value has to be a valid numeric literal of the output data type, otherwise the function returns the value 0 and the runtime error 'Format string failure' occurs (see the note below).
- Additional characters except than whitespaces after or before the numeric literal are not permitted. The function returns the value 0 and generates a 'Format String Failure' if the string value contains unallowed characters.
- All leading and trailing whitespaces in the input string are ignored.ASCII codes regarded as whitespaces:
Character | Value |
Horizontal tab | 9 (09h) |
Line feed | 10 (0Ah) |
Vertical tab | 11 (0Bh) |
Form feed | 12 (0Ch) |
Carriage return | 13 (0Dh) |
Blank | 32 (20h) |
- If the input value is out of the range for the output data type, the overflow value is returned and the runtime error 'Format string failure' occurs (see the note below).
- Binary, octal, hexadecimal and decimal integers are allowed. For example:INT#2#0101 (binary representation of 5)INT#8#606 (octal representation of 390)INT#10#100 (decimal representation of 100)INT#16#00FA (hexadecimal representation of 250)
Note
Controller stop on string error: The controller can be automatically stopped when a string error occurs. This allows you to locate the error in your project. To enable the automatic stop of the controller in case of a string error, activate the button in the Cockpit toolbar of the controller. |
Note: If the range and precision of the input data type can be mapped to the range and precision of the output type, an implicit type conversion can be performed instead of using this function. For the TO_LREAL function, this applies to REAL, DINT, INT, SINT inputs as well as for UDINT, UINT and USINT. |
Error behavior
| Error behavior
The following table shows the errors which may occur while executing the function and the value returned by the function in the corresponding error case. As described, the value returned by the function in the error case depends on the value of the input (for example, if the input value of data type REAL is not a legal number (NaN), NaN is returned).
Error case | Output value |
Real: NaN | NaN |
Real: inf+ | Inf+ |
Real: Inf- | Inf- |
|
Additional information
| EN/ENO behavior
The POU is only executed if TRUE is applied to the EN input. If EN = FALSE, the POU is not executed and ENO = FALSE indicates the inactivity.
If any of the errors listed under "Error behavior" occurs while executing the function, ENO is set to FALSE.
|